#make server based

54 messages · Page 1 of 1 (latest)

hidden urchin
#

someone made this following script for me:

local part = workspace["boxthing"]
local Player = game.Players.LocalPlayer
local character = Player.Character

con = game:GetService("RunService").RenderStepped:Connect(function()
part.Position = Vector3.new(character.HumanoidRootPart.Position.X,part.Position.Y,character.HumanoidRootPart.Position.Z)
end)

the issue is it doesnt interact with other things properly (this is in the StarterCharacterScripts) because its local, could someone rewrite this to be server-based? (max players per server is 1)

jaunty oriole
#

just get PlayersAdded() and CharacterAdded()

hidden urchin
jaunty oriole
hidden urchin
#

sorry if i sound stupid i am new to coding

jaunty oriole
#

well you would make it a normal script in ServerScriptService

#
game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(character)
    -- whatever you need to do to the character
  end
end
hidden urchin
#

oh thanks

jaunty oriole
#

yup

hidden urchin
#

lemme add this to the game im making now

#

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local part = workspace["boxthing"]
local Player = game.Players.LocalPlayer
local character = Player.Character

    con = game:GetService("RunService").RenderStepped:Connect(function()
        part.Position = Vector3.new(character.HumanoidRootPart.Position.X,part.Position.Y,character.HumanoidRootPart.Position.Z)
    end)
end)

end)

#

this errors at line 5 with: attempt to index nil with 'Character'

#

@jaunty oriole can you fix this

jaunty oriole
#

you can't use "LocalPlayer" in a server script

#

that only applies to localscript for a player

#

instead, since we already defined "player" in the PlayerAdded function you would use that

#

it's a parameter 😮

hidden urchin
#

oh ok

#

so i delete lines 4 and 5?

hidden urchin
#

@jaunty oriole

#

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local part = workspace["boxthing"]

    con = game:GetService("RunService").RenderStepped:Connect(function()
        part.Position = Vector3.new(character.HumanoidRootPart.Position.X,part.Position.Y,character.HumanoidRootPart.Position.Z)
    end)
end)

end)

#

it errors with: RenderStepped event can only be used from local scripts

jaunty oriole
#

because you can’t do that in localscripts, duh

hidden urchin
#

yeah but

#

what do i replace it with

#

for something that i can use for a global

jaunty oriole
#

do the “Heartbeat” event instead

#

you would need to get the RunService tho

hidden urchin
#

Ok ill try that

#

it works but its a bit delayed

#

like lemme show a video

#

@jaunty oriole

jaunty oriole
#

so would you want it to be literally stuck to the player?

#

because if you really wanted to you could just use a WeldConstraint and offset it to your liking with the player character

hidden urchin
#

but how would i use that

#

i never heard of that

jaunty oriole
#

do something like this

-- whenever the character is added above, do this:
local weld = Instance.new("WeldConstraint")
weld.Part0 = character.HumanoidRootPart
weld.Part1 = part
#

and you wouldn't need to loop anything because we're literally just creating an object that connects the parts together

#

obviously you might need to adjust some stuff like the position but yeah

hidden urchin
#

oh alr

#

thanks

#

@jaunty oriole

#

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local weld = Instance.new("WeldConstraint")
weld.Part0 = character.HumanoidRootPart
weld.Part1 = workspace.boxthing
end)
end)

#

like this?

#

cus it does nothing

jaunty oriole
#

any errors?

#

that’s not supposed to be the full script btw

#

you would define all the variables beforehand

hidden urchin
#

no errors

jaunty oriole
#

is that the full script?

#

if not send the full script