Remote doesn't fire. I don't understand why

I have looked on the Developer Hub, but I couldn’t find my answer.

local Buy = game.StarterGui.Shop.Background.StarShop.SkipStage.Buy
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Function

Buy.MouseButton1Click:Connect(function(player)

	ReplicatedStorage.Shop.StarShop.SkipStage:FireClient(player)
	
	print("Eventfired")

end)

The script above should fire a RemoteEvent named ‘‘SkipStage’’, when the person clicked on the ‘‘Buy’’ button from the shop, it should fire the event.

I’m just a beginner and I would like help. It is very much appreciated.

Edit: if you need more information, feel free to ask.

  • Where’s the script located?
  • You can’t use FireClient() on a client-side it should be FireServer()

It is in the ServerScriptService, in a normal script.

  • You can’t use this in a normal Script: Buy.MouseButton1Click:Connect(function(player)

The player can’t click on StarterGui. you will need to get the PlayerGui of the Player instance.

So basically, it would be game.PlayerGui.Shop.Background.StarShop.SkipStage.Buy?

First you’ll need to get the player. I’d say loop through the players if it’s a server-side script.

No, player gui is inside the player.

example: game:GetService(‘Players’).LocalPlayer:WaitForChild(‘PlayerGui’)

1 Like
local Buy = script.Parent
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("SkipStage")

Buy.MouseButton1Click:Connect(function()
    event:FireServer()
    print("Server event fired")
end)

You cannot detect mouse-clicks from a server-side script in a GUI.
Make the above script a LocalScript and place it as a child of your Buy button, then it will fire the server.

I’m also assuming SkipStage is a RemoteEvent in ReplicatedStorage, so now you just need to make a server-script to finalise the purchase when the RemoteEvent is received.

2 Likes

Here’s what you gonna do:

First, create a localscript inside of the Buy button and put the code like this:

local buyBTN = script.Parent -- Instance to the Buy button
local Remote = -- Instance to the Remote

buyBTN.MouseButton1Click:Connect(function() --This doesn't have a parameter
    Remote:FireServer() -- This contains an automatic parameter
end)

Next, on the normal Script should contain:

local Remote = -- Instance to the Remote

Remote.OnServerEvent:Connect(function(playerSender)
    print(playerSender.Name, "called the Remote!") -- Sorbious called the Remote!
end)

The playerSender is a default parameter once the Remote has been called.

2 Likes

Oh, thank you! I think this will work; I appreciate it! I will let you know if it really works.

By the way: thank all of you that you took your time to help me.

The server event is fired.

So what I’ll do now is:

game.ReplicatedStorage.Shop.StarShop.SkipStage.OnServerEvent:Connect(function()

Does the function work for the whole server, or just the player who clicked on ‘‘Buy’’?
I was wondering because it is a serverevent.

Edit: this script is in the ServerScriptService in a normal script.

Now you need to include the player variable inside the parentheses to ensure it only completes the action for the player who fired the RemoteEvent (you only need to include this in the server-script).

I’d also recommend you changing the Instance in the LocalScript I provided to where your RemoteEvent actually is in ReplicatedStorage as I didn’t realise it was in a different directory.

1 Like

Thank you, I already did that!^

So it’d become:

game.ReplicatedStorage.Shop.StarShop.SkipStage.OnServerEvent:Connect(function(player)

right?

Yes, I’d recommend predefining the variables in-case the script loads in before the Instances, however.

local RS = game:GetService("ReplicatedStorage")
local Shop = RS:WaitForChild("Shop")
local StarShop = Shop:WaitForChild("StarShop")
local event = StarShop:WaitForChild("SkipStage")

event:OnServerEvent:Connect(function(player)
    print("Server fired by".. player.Name)
    -- code here
end)
1 Like

You should check and try my recommendation first.

1 Like

Yea thank you too a lot! I will test that too, after waIshuk’s one.

Sorbious and waIshulk:
Both of your answers worked and helped me a lot: thank you for your time, and sharing your knowledge with other people (me in this case).

I can’t mark both as solution (even though they are both solution-worthy), so I will mark the first reply as solution (post by waIshuk). Sorry for that.

But thanks to both of you this script works now. Thank you so much!