I have an issue with my rolling system, I tested it with a friend and he said the roll only shows up for the player who rolled it. Is there anyway to fix this?
The code for each button:
local Switch = script.Parent
local function rollDice(): number
return math.random(1, 10)
end
local Debounce = false
Switch.MouseButton1Click:Connect(function()
if not Debounce then
local Nums = rollDice()
script.Parent.Text = “Cooldown!”
Debounce = true
script.Parent.Parent.Parent.Counter.TextLabel.Text = “Calculating Roll…” – for some suspens
wait(2)
workspace.sfx:Play()
script.Parent.Parent.Parent.Counter.TextLabel.Text = "Your Regular Roll Is - "…Nums
wait(10)
Debounce = false
script.Parent.Text = “Normal Dice Roll”
end
end)
To make the roll show up for everyone, you’d need to use a RemoteEvent to communicate to the server that a roll has occurred. For example:
-- LocalScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = replicatedStorage.remoteEvents
local Switch = script.Parent
local function rollDice(): number
return math.random(1, 10)
end
local function showRoll(Nums)
script.Parent.Parent.Parent.Counter.TextLabel.Text = "Your Regular Roll Is - "…Nums
end
remoteEvents.showRoll.OnClientEvent:Connect(function(Nums)
showRoll(Nums)
end)
local Debounce = false
Switch.MouseButton1Click:Connect(function()
if not Debounce then
local Nums = rollDice()
script.Parent.Text = “Cooldown!”
Debounce = true
script.Parent.Parent.Parent.Counter.TextLabel.Text = “Calculating Roll…” – for some suspens
wait(2)
workspace.sfx:Play()
showRoll(Nums)
remoteEvents.ShowRoll:FireServer(Nums)
wait(10)
Debounce = false
script.Parent.Text = “Normal Dice Roll”
end
end)
--ServerScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvents = replicatedStorage.remoteEvents
remoteEvents.ShowRoll.OnServerEvent:Connect(function(player, Nums)
ShowRoll:FireAllClients(Nums)
end)
You should probably add sanity checks to prevent exploiters from spamming the remote, changing their random number…
You should put the localscript in the same place that the original localscript was in. Afterwards, add the serverscript part to any Script you have (preferably in ServerScriptService). Create a folder called “RemoteEvents” in ReplicatedStorage and put a RemoteEvent called “ShowRoll” inside.