Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Driver Seat Drive For Cash?

Asked by 4 years ago

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
You can't access game.Players.LocalPlayer from a server script. MrLonely1221 701 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)
Ad

Answer this question