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

Click Detector leaderstats remote event not working?

This Script is located in game.ServerScriptService





game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Cash = Instance.new("IntValue", leaderstats)
	Cash.Name = "Cash"
end)






game.ReplicatedStorage.CashClickerEvent.OnServerEvent:Connect(function(player)
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
	
end)


The second script to trigger the RemoteEvent is located in game.Workspace

local remoteEvent = game.ReplicatedStorage:WaitForChild("CashClickerEvent")
local ClickDetector = game.Workspace.Part.ClickDetector








ClickDetector.MouseClick:Connect(function()
	remoteEvent:FireServer()
end)

2 answers

ServerScriptService

game.ReplicatedStorage.CashClickerEvent.OnServerEvent:Connect(function(player, Click)
	if Click == "Fire" then
 	      player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
	end
end)

Second script

ClickDetector.MouseClick:Connect(function()
    remoteEvent:FireServer("Fire")
end)

8 comments

0

Didn't resolve my issue, i don't see why you would put "Fire" strings?

0

Is the second script local ?

0

Second script is Local, Yes.

0

Try put print("Yes") instead of 'player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1'

0

Maybe only there is an error in this line

0

I followed your steps, and it did not print yes.

0

Are you sure the mouseClick function works? Try create print

0

How do i create print with remote events? If it's just putting remoteEvent:FireServer() in the local script while in the main script you have print("hi") is the case, then it didn't print anything

local Players = game:GetService("Players")
-- [[Server Script]]
Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	local Cash = Instance.new("IntValue", leaderstats)
	Cash.Name = "Cash"
end)
workspace.Part.ClickDetector.MouseClick:Connect(function(plr) -- Can be used on Server. WILL WORK! Doesnt need to be in second script, Players.PlayerAdded wont yield, Players.PlayerAdded and ClickDetector.MouseClick is a RBXScriptSignal.
	plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 1
end)

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