Text only showing clientsided

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)

2 Likes

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…

I’m kinda confused lol

You want that to show that UI on everyone’s screen no matter who rolled it?
wouldn’t that get annoying with to many players

But if that’s the game your aiming towards you should probably use a server script along with a local script. By using @Cxsnls script above

Quick question, where are the local and server sided scripts located like the local script in the button? I’m a bit confused

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.

No, it’s meant to be for my friends with a hosting system, so only the host team will have access to the GUI

I will tell you if I encounter any errors

1 Like

I think the serversidescript (the one that fires the remote event so everyone can see it) and the cooldown are broken.

I opened up my alt account and began testing, but I did not get any changed text on my alt

Change this line:

remoteEvents.ShowRoll.OnClientEvent:Connect(function(Nums)
    showRoll(Nums)
end)

What about the cooldown? Is there anyway to fix that.

Nevermind it does work, but let me make sure the text pops up for every player.


What is the soloution to this?

What’s the problem?
Does it not replicate?

It does not make the roll show for the player on the left.

Got it. I must’ve forgotten something before.
Change this in the ServerScript.

remoteEvents.ShowRoll.OnServerEvent:Connect(function(player, Nums)
    remoteEvents.ShowRoll:FireAllClients(Nums)
end)

Sorry for all the mistakes.

Will test, replying soon. Will report any errors found

The result is still being faulty, Is this the correct way to do it?

If that’s not it, I have no idea what it is. Do you see any errors on the console? (F9, click server).