FireServer() not working for me

I don’t know why but I have the impression that the FireServer() does not work for me, or does it not work at all?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer()
end)

I tested it on a script it does not work

It should be done on a local script.

Other than then any errors or print?

Did you try using print() before firing the remote event to check if that part of the script is actually running?

If not, try that.
If it’s running and still not working, make sure your using the correct way.
On the server script there should be something like this:

RemoteEvent.OnServerEvent:Connect(function()
– your code here
end)

Remote Events

Yes sorry it is a localscript, An error that occurs “FireServer can only be called from the client”

I tried with print and the server receives the information when I click on the button. The problem is that when I put the FireServer() the localscript crashes.

Weird, one thing I can tell you is maybe you can use .Activated instead of MouseButton1Click.

I’m not sure why the script is crashing, do you have any loops?

My goal is just to make a button and when you click on it the number of agents you have goes down like $100, -$5 goes away. I need to do a remote event to signal the server that the value is changing. But the problem is that roblox never works, there is always a problem and it annoys me, when you solve one, another problem comes. :frowning:

1 Like

I don’t think this problem is related to roblox, since my remote events work correctly. To check if the value changed, there is a better way.

local Money = Instance.new(“IntValue”) – (Use your real value if you have one already)

Money:GetPropertyChangedSignal(“Value”):Connect(function())
– rest of script here, example:
Money.Value -= 5 – Reduces the amount of money by 5
end)

What is the RunContext of the script?

The runcontext of all my scripts including localscripts are on “Server”

Oh, a remote event can’t be fired from a server script. That is probably the problem.

I will try this script to see if it works.

1 Like

I have an error in output like this.

What is the error you got? I might have wrote something wrong. Also, this alone won’t work, how does your cash system work? Does it use IntValues?

Edit: Oh wait, I thought your replying to my other reply

Have you tried putting the runcontext to legacy instead of server. If that doesn’t work try adding a new script and copying the script over.

Thank you very much for your help, I don’t want to bother you with all my problems.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = leaderstats
end)

I tried Server or Legacy except client side.

Ok, in that case my script needs to be changed a little:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player.leaderstats
local money = leaderstats.money

  money:GetPropertyChanged("Value"):Connect(function)
         -- your script here, example:
        money.Value -= 5     -- reduces 5 money from your total
  end)

end)

This script will run everytime the value of money changes, I’m not sure what you needed exactly.

I just need that when you click a button, the money you have Possess goes down.

You mean like if you click a button, your money just decreases by 5?

Local Script: (In starter player)
local GUI = script.Parent – change this to your button
local RemoteEvent = game.ReplicatedStorage.RemoteEvent – you should probably rename the remote event
GUI.Activated:Connect(function()
RemoteEvent:FireServer()
end)

Server Script (In server script service)

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(Player)
Player.leaderstats.money.Value -= 5
end)

The script might have some errors because I didn’t write this in studio.