Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click Detector leaderstats remote event not working?

Asked by
ZO0PPY 25
4 years ago

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

Log in to vote
0
Answered by
InLeXiX 18
4 years ago

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)
0
Didn't resolve my issue, i don't see why you would put "Fire" strings? ZO0PPY 25 — 4y
0
Is the second script local ? InLeXiX 18 — 4y
0
Second script is Local, Yes. ZO0PPY 25 — 4y
0
Try put print("Yes") instead of 'player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1' InLeXiX 18 — 4y
View all comments (4 more)
0
Maybe only there is an error in this line InLeXiX 18 — 4y
0
I followed your steps, and it did not print yes. ZO0PPY 25 — 4y
0
Are you sure the mouseClick function works? Try create print InLeXiX 18 — 4y
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 ZO0PPY 25 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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)

Answer this question