Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Driver Seat Drive For Cash?

It shows in Developer Console that in line 6 that LocalPlayer is wrong. someone pls help. I don't know what else to put?

local datastore = game:GetService("DataStoreService")
	local ds1 = datastore:GetDataStore("CashSaveSystem")
	 
	game.Players.LocalPlayer.WaitForChild("leaderstats")
	game.Players.LocalPlayer.leaderstats.WaitForChild("Cash")
	M = game.Players.LocalPlayer.leaderstats
	 
	MinSpeed = 15 --Player must be going this fast in SPS to earn money.
	 
	while wait(0.65) do
	    script.Parent.DropMenu.CashAmount.Value = script.Parent.DropMenu.TextBox.Text
	    script.Parent.Money.Text = "Money: $"..M.value
	    if game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Magnitude > MinSpeed and game.Players.LocalPlayer.Character.Humanoid.Sit == true then
	        M.Cash = M.Cash + game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Magnitude / 1.4
	    end
	end

1 comment

1

You can't access game.Players.LocalPlayer from a server script.

1 answer

✓ Accepted answer

You are trying to get the player but you are doing it in the wrong way. In order to get the player who is sitting on the driver's seat do this:

script.Parent.ChildAdded:connect(function(weld)
	local char = weld.Part1.Parent
	local player = game.Players:FindFirstChild(char.Name)
	print(player)
	if player ~= nil then
		print('player is here',player)
		-- Now insert your script below
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.