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

Why doesn't this script fireclient () properly?

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

✓ Accepted answer

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

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.

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