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

Why doesn't this script fireclient () properly?

Asked by 4 years ago

i am trying to make a script which gives the player money when they deliver the lumber. It worked when i had it set to FireAllClients, but it would add money to everyone.

heres the code:

    local pad = script.Parent
    local debounce = false
    local player = game.Players.LocalPlayer
    pad.Touched:Connect(function(part, arg)
        if not debounce then
            debounce = true 
            if part.Name == "WheeLumber" then
            elseif part.Parent.VehicleSeat.load.Value == "lumber" then
            local car = part.Parent
                    print"bruh"
                    car.logs:Destroy()
                    game.ReplicatedStorage.RemovePlayerMoneyEvent:FireClient(player,arg)
                    debounce=false
                    wait(6)
            end

        end

    end)


2 answers

Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
4 years ago
Edited 4 years ago

LocalPlayer cannot be used on the server. What you could do is get the Humanoid sitting in the vehicle with VehicleSeat.Occupant and do Players:GetPlayerFromCharacter(VehicleSeat.Occupant.Parent)

developer.roblox.com:

LocalPlayer

Occupant

GetPlayerFromCharacter

Don't forget to mark this as the solution if it solved your problem :)

Ad
Log in to vote
3
Answered by 4 years ago

You cannot use :FireClient() in a LocalScript. :FireClient() must be used in a Server Script in order for it to fire. In the LocalScript, you would use .OnClientEvent to connect the two together.

Read more about :FireClient() here.

Answer this question