RemoteEvent not firing

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a part that when you click it an remote event gets fired to give the player a point
  2. What is the issue? Include screenshots / videos if possible!
    The remoteEvent is not firing here is the script that fires the remote event:
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	print("Clicked")
	game.ReplicatedStorage.RemoteEvents.RemoteEvent:FireClient(plr,1,1)
	print("Worked")
end)

And here is the local script that responds when the event gets fired:

script.Parent.OnClientEvent:Connect(function(plr,multiplied,Rebirths)
	local Requirement = plr.leaderstats.RebirthCost.Value * multiplied
	if plr.leaderstats.TimeWasted.Value >= Requirement then
		print()
		plr.leaderstats.Rebirths.Value += Rebirths
	end
	print("Worked")
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    It didn’t help.
2 Likes

Why did you place a local script in the Replicated Storage in the first place?

1 Like

Changing things like leaderstats should be done by the server, as it is not replicated to other clients (or the server) if done on the client.

You should instead remove the local script you have and just have this as a server script inside the part:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	local Requirement = plr.leaderstats.RebirthCost.Value * 1
	if plr.leaderstats.TimeWasted.Value >= Requirement then
		print()
		plr.leaderstats.Rebirths.Value += 1
	end
	print("Worked")
end)

I would also like to point out that it is good practice to use Instance:WaitForChild() when dealing with leaderstats depending on how your data is handled. If a player joins the game and clicks the part before their leaderstats have been created, the script will break.

Oh yeah i forgot to mention the fact that i am trying to make it so the billboardgui text changes for the local player

You’ll have to provide us with information on how your BillboardGui is structured and also any code you have that is already modifying the BillboardGui if you’d like help with that.

Move the local script to somewhere else such as the Starter Gui, it won’t function in the Replicated Storage.

Here is the local script that responds when the event gets fired but it also changes the text gui

script.Parent.OnClientEvent:Connect(function(plr,multiplied,Rebirths)
	local Requirement = plr.leaderstats.RebirthCost.Value * multiplied
	if plr.leaderstats.TimeWasted.Value >= Requirement then
		print()
		plr.leaderstats.Rebirths.Value += Rebirths
		game.Workspace.Part1.BillboardGui.TextLabel.Text = "Cost"..Requirement.." TimeWasted Points"
	end
	print("Worked")
end)

You need to move the local script

I tried your solution but it brings this error

 [Players.zaydoudou.PlayerScripts.LocalScript:2: attempt to index number with 'leaderstats']

The solution I provided still applies, but then also put this into a local script in StarterPlayer → StarterPlayerScripts.

local player = game:GetService("Players").LocalPlayer
local rebirthCost = player:WaitForChild("leaderstats"):WaitForChild("RebirthCost")

local part = workspace:WaitForChild("Part1")
local gui = part:WaitForChild("BillboardGui"):WaitForChild("TextLabel")

function UpdateLabel()
	local cost = rebirthCost.Value * 1
	gui.Text = "Cost "..cost.." TimeWasted Points"
end

UpdateLabel()
rebirthCost:GetPropertyChangedSignal("Value"):Connect(UpdateLabel)

This script essentially runs a function whenever the RebirthCost value changes. I do not think a RemoteEvent is necessary here unless the multiplier needs to be sent by the server.

The player is not passed as an argument to the client with a remote event even though you need it on the server to fire the event

Is there any other way to make the function run without having to get fired everytime the rebirthCost Changes?

Is there a particular reason you would need to fire it at a different time? I’m not familiar with how your game is meant to operate.

Well the game is supposed to work like this:
1.You get points for every second (TimeWasted)
2.Once you get enough points you can go to the part to rebirth (i can make it as a gui but my friend @CrazyD4RKiller told me to make it as a part for some reason since he is the owner of the game)
3. And then you get more points per second after rebirthing
4.Repeat

Alright. Is there a reason the label would need to update other than when the cost changes, though? Logically it should only need to update if there is a difference in the cost.

The text label would need to update to show how much points (TimeWasted) you need to rebirth and it should only affect for the local player

That is exactly what it should be doing. As I said above, make sure the last code snippet I posted is located in a local script in StarterPlayer → StarterPlayerScripts.

That’s what i did i replaced it with game.ReplicatedStorage.RemoteEvents.RemoteEvent.OnClientEvent:Connect(UpdateLabel) but it prompts this error

Attempt to connect failed: Passed value is not a function

Can you show the full script? I think something else might be going on here.

Here is the script:

local player = game:GetService("Players").LocalPlayer
local rebirthCost = player:WaitForChild("leaderstats"):WaitForChild("RebirthCost")

local part = workspace:WaitForChild("Part1")
local gui = part:WaitForChild("BillboardGui"):WaitForChild("TextLabel")

function UpdateLabel()
	local cost = rebirthCost.Value * 1
	gui.Text = "Cost "..cost.." TimeWasted Points"
end
UpdateLabel()
game.ReplicatedStorage.RemoteEvents.RemoteEvent.OnClientEvent:Connect(UpdateLabel)  --Changed it because i don't want to make it so it fires it when the rebirthCost changes