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

Remote Event Not Firing From Tool?

I have a script where I want the tool to activate, play an animation and then give the player money.

I have a RemoteEvent called 'Money' in ReplicatedStorage and am firing it from the following local script:

*local Amount = 5


script.Parent.Activated:connect(function()
	if script.Parent.Used.Value == true then
		
	else
		script.Parent.Used.Value = true
		 local hum = game.Players.LocalPlayer.Character.Humanoid
		local anim_feet = hum:LoadAnimation(script.Parent.Animation)
		local current = anim_feet
	current:Play()--How long until animation plays.
	wait(0.5)
	game.ReplicatedStorage.Money:FireServer(Amount)
	script.Parent.Used.Value = false
		end
	end)
*

I then have the Server Script in ServerScriptService:

*local function onMoneyFired(Player,Amount)
	Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + Amount
end

game.ReplicatedStorage.Money.OnServerEvent:Connect(function(onMoneyFired)
	print("Fired")
end)*

My problem is the animation plays but none of the server script works. I have checked all over the internet for a solution but I cant find anything. I do receive the 'Fired' that I print in the bottom of the server script but nothing happens after that.

1 comment

0

the thing you messed up is you used (function(onMoneyFired) instead of (onMoneyFired)

1 answer

✓ Accepted answer

You are incorrectly receiving the function on the server.

By creating a literal function by giving Connect() said function instead of the local function you just created, a new function will be created with the first parameter, the same name as the local function, being assigned to the client that fired the event to the server.

This is a really simple fix. You can either:

  • Replace the Connect() line with this line:
game.ReplicatedStorage.Money.OnServerEvent:Connect(onMoneyFired)

or...

  • Replace the Connect() line with the above line, except that you would also assign Connect() to a variable. The benefit here is that Connect() returns an RBXScriptConnection when the RBXScriptSignal (event) associated with it fires:
local func = game.ReplicatedStorage.Money.OnServerEvent:Connect(onMoneyFired)

Choosing option 2 also allows you to Disconnect() the event in case something goes wrong (because you get an RBXScriptConnection assigned to func):

func:Disconnect()

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