D20 roleplay roler

I’ve tried many things, but nothing has worked. and I’m stumped and need advice

This is ment to be a D20 dice roller using billboard GUI.

Although it slightly works, it acts as one thing, other players can’t roll at the same time. And when one player rolls, it will sometimes appear on another players head.

  • Server Side Script ( In ServerScript Service )
local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local Debouce = false

local Players = game:GetService("Players")

local RandomRolls = {
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",	
	"8",
	"9",
	"10",
	"11",
	"12",
	"13",
	"14",
	"15",
	"16",
	"17",
	"18",
	"19",
	"20",
}


event.OnServerEvent:Connect(function(Plr)
	if Debouce == true then return end
	Debouce = true
	
	local Character = Plr.Character 

	print(Character)

	local RandomRoll = RandomRolls[math.random(1, #RandomRolls)]
	print(RandomRoll)

	script.RollSound:Clone().Parent = script
	script.RollSound.Parent = Character.Head
	Character.Head.RollSound:Play()


	script.OverHeadGui:Clone().Parent = script
	script.OverHeadGui.Parent = Character.Head
	script.OverHeadGui.Adornee = Character.Head

	Character.Head.OverHeadGui.TextLabel.Text = RandomRoll

	wait(4)
	Debouce = false
	Character.Head.RollSound:Destroy()
	Character.Head.OverHeadGui:Destroy()
	end)

  • Client Side
local Character = game.Players.LocalPlayer.Character

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	event:FireClient()
end)

you can add a coroutine to fix the players rolling at the same time, but for the head, send over the player that clicked the button and change the guy only for that person.

You are using :FireClient() inside a local script, and the reason other players cannot roll is because you are using debounce on the server side, which will make the script only works when the debounce is false (For everyone).

This setup will allow other users to roll at the same time and might fix the issue where GUI shows on another player’s head:

Server Script:

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local Debouce = {}

local Players = game:GetService("Players")

local RandomRolls = {
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",	
	"8",
	"9",
	"10",
	"11",
	"12",
	"13",
	"14",
	"15",
	"16",
	"17",
	"18",
	"19",
	"20",
}


event.OnServerEvent:Connect(function(Plr)
	if table.find(Debouce,Plr) then return end
	table.insert(Debouce,Plr)

	local Character = Plr.Character 

	print(Character)

	local RandomRoll = RandomRolls[math.random(1, #RandomRolls)]
	print(RandomRoll)

	local sound = script.RollSound:Clone()
	sound.Parent = Character.Head
	Character.Head.RollSound:Play()
	print("Sound played")


	local oveheadui = script.OverHeadGui:Clone()
	oveheadui.Parent = Character.Head
	oveheadui.Adornee = Character.Head

	Character.Head.OverHeadGui.TextLabel.Text = RandomRoll

	wait(4)
	table.remove(Debouce,Plr)
	Character.Head.RollSound:Destroy()
	Character.Head.OverHeadGui:Destroy()
end)

Client:

local Character = game.Players.LocalPlayer.Character

local event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)
1 Like

Although it fixes players being able to roll for other players, however the script makes it so the players can only roll once, then it just doesn’t work.

1 Like

Wait Nevermind, i fixed it by putting the debouce in the local script, thanks for all the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.