Hello there, I am currently trying to make a vehicle spawner for my game. I have started off with creating a LocalScript finding the character of the player in the workspace. I got that in a value. Now whenever I try to make use of that value, it returns nil.
I don’t see why it’s returning nil however you might as well use the LocalPlayer’s Character, as long as that doesn’t present any other issues:
u cant call script.Parent.Spawner.Value.HumanoidRootPart.Position
u should use:
local char = game.Workspace:FindFirstChild(script.Parent.Spawner.Value)
if char then
local Torso = char.Torso or char.HumanoidRootPart
if Torso then
Clone:MoveTo(Torso.CFrame)
end
end
You shouldn’t be using a non-local script in PlayerGui. The local script updating the spawn value won’t update it for the server script, and the server script probably won’t even run properly.
Oh I just noticed you’re setting the Spawner value in a local script, but then try to access it from the server. The server will not see changes you make in a local script.
Also as mentioned, don’t put server scripts in the player gui. They don’t go there and you shouldnt rely on it working.
I don’t see why the value is nil though, probably because you call it before the value is set
Edit: @madattak is right, the server will not replicate any changes done on the client, and normal scripts should not be in PlayerGui.
The server script should be placed in ServerScriptService and you will have a RemoteEvent. The server script will handle the RemoteEvent with OnServerEvent and will create and teleport the car to the player. In the local script, when the player presses the GUI button, you should fire that event to the server
I now see what the problem is, but I think that I am not far enough with my programming skills for all that RemoteEvent stuff, thanks for your help anyway.