Help with my roblox roll system

Hello, I am trying to make a game where you are supposed to roll a dice and jump to get money but if there is more than 1 player in a server it bugs out.

In the video the person in the quest goes up by two instead of one and also the dice gets stuck after a few rolls (the dice takes multiple jumps to pop it but i think its because im really laggy)

local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("ownedDiceData")

game.ReplicatedStorage.remotes.clickRe.OnServerEvent:Connect(function(plr)
	print(plr)
	local clickDb = plr:WaitForChild("clickDb")
	local doneDb = plr:WaitForChild("doneDb")
	doneDb.Value = false

	if clickDb.Value == false then
		game.ReplicatedStorage.remotes.clickRe:FireClient(plr)
		clickDb.Value = true
		plr.Character.Humanoid.WalkSpeed = 0
		workspace["Dice Shake 7 (SFX)"].Playing = true
		for i,v in pairs(game.ReplicatedStorage.Dice:GetChildren()) do
			if v.Name == plr:WaitForChild("equippedDie").Value then
				local dupe = v:Clone()
				local popDupe = game.ReplicatedStorage.Dice.popEffect:Clone()
				dupe.Parent = game.Workspace

				while task.wait() do
					if doneDb.Value == false then
						if plr.Character.Humanoid.Jump == false then
							dupe.Orientation += Vector3.new(0, 10, 10)
							dupe.Position = Vector3.new(plr.Character.HumanoidRootPart.Position.X, plr.Character.HumanoidRootPart.Position.Y + 6 ,plr.Character.HumanoidRootPart.Position.Z)
							game.Players.PlayerRemoving:Connect(function(playerRemove)
								if playerRemove.Name == plr.Name then
									dupe:Destroy()
								end
							end)
						else
							plr.leaderstats.Rolls.Value += 1
							game.ReplicatedStorage.remotes.rolledEvent:FireClient(plr)
							workspace["Dice Shake 7 (SFX)"].Playing = false
							workspace["Poof sound"]:Play()
							popDupe.Parent = dupe.Parent
							popDupe.CFrame = dupe.CFrame
							dupe.Orientation = Vector3.new(0, 179.75, 0)

							plr.Character.Humanoid.WalkSpeed = 16

							for i,v in pairs(dupe:GetChildren()) do
								if v.Name == "val1" then
									local vals = v.Parent:GetChildren()
									local chosen = vals[math.random(1,#vals)]
									local BilClone = game.ReplicatedStorage.Dicenumbil:Clone()
									plr:WaitForChild("leaderstats").Money.Value += chosen.Value
									BilClone.Parent = dupe
									BilClone.Frame.DiceNumber.Text = tostring(chosen.Value) .. "$"
								elseif v.Name == "minVal" then
									local rand = math.random(dupe.minVal.Value, dupe.maxVal.Value)
									plr:WaitForChild("leaderstats").Money.Value += rand
									local BilClone = game.ReplicatedStorage.Dicenumbil:Clone()
									BilClone.Parent = dupe
									BilClone.Frame.DiceNumber.Text = rand .. "$"
								end
							end

							doneDb.Value = true

							wait(1)

							dupe:Destroy()
							popDupe:Destroy()


							repeat wait(0.1) plr:WaitForChild("PlayerGui").rollScreen.Roll.RollButton.timer.Value -= 0.1 until plr:WaitForChild("PlayerGui").rollScreen.Roll.RollButton.timer.Value <= 0
							plr.PlayerGui.rollScreen.Roll.RollButton.timer.Value = 5
							clickDb.Value = false
						end
					end
				end
			end
		end
	end
end)


game.Players.PlayerAdded:Connect(function(plr)
	repeat 
		task.wait()
	until 
		plr.Character
		task.wait(3)
	local success, dice = pcall(function()
		return playerDataStore:GetAsync(plr.UserId)
	end)
	if success then
		for i,v in pairs(dice or {}) do
			local dice2 = game.ReplicatedStorage.Dice:FindFirstChild(v)
			if dice2 then
				local clone = dice2:Clone()
				clone.Parent = plr:WaitForChild("ownedDice")
			end
		end
	end

	game.ReplicatedStorage.remotes.moneyCheckRe.OnServerEvent:Connect(function(plr, price, dice)
		local ownedDice = plr:WaitForChild("ownedDice")
		local isOwned = false

		for i,v in pairs(ownedDice:GetChildren()) do
			if v.Name == dice.Name then
				isOwned = true
			end
		end

		if isOwned then
			plr:WaitForChild("equippedDie").Value = dice.Name
			game.ReplicatedStorage.remotes.changeTextRe:FireClient(plr, dice.Name)
		else
			if plr:WaitForChild("leaderstats").Money.Value >= price then
				plr:WaitForChild("leaderstats").Money.Value -= price

				local clone = dice:Clone()
				clone.Parent = ownedDice
				plr:WaitForChild("equippedDie").Value = dice.Name
				game.ReplicatedStorage.remotes.changeTextRe:FireClient(plr, dice.Name)

				game.Players.PlayerRemoving:Connect(function(leavingPlayer)
					local diceTable = {}

					for i,v in pairs(leavingPlayer:WaitForChild("ownedDice"):GetChildren()) do
						if v and v:IsA("UnionOperation") then
							table.insert(diceTable, v.Name)
						end
					end

					local success, err = pcall(function()
						return playerDataStore:SetAsync(leavingPlayer.UserId, diceTable)
					end)

					if not success then
						print(err)
					end
				end)
			end
		end
	end)
end)
1 Like

Also when I test it in multiplayer I think that the quest amount goes up by however many people are in the server

1 Like

You should move this post to #help-and-feedback:scripting-support.

2 Likes

how do i do that sorry im new to posting on devforum

nevermind i figured it out sorry

love the code you made looks sick reminds me of mario party. but yea i’d assume it’s because the parts where there is no number in the while task.wait() it may cause it to be bugging try adding 0.005 to it and see what happens, cause i had an issue with a similar bug and that’s what fixed it for me but that was just me messing up and working on something different so idk

thx I tried what you said to do but i dont think it worked

i don’t doubt it. i’m still learning i was just guessing based on having a similar issue. hope you can get it fixed though. good work

i figured out a little bit on what is happening so It also works with only 1 player in the server if you hold down jump and spam e or the button the timer goes super fast and duplicates a ton of dice

i assume it being related to it running too fast at a point in the code. like if it works but overtime it starts glitching out and theres no error then it usually is from the loops running too fast that’s also why i suggested it being the while true loops you added. my code i was working on did a similar thing meaning the code was working just fine but then over time it got buggy and broke a section aka the flow it had… also looks like if it’s duplicating too much then it’s usually also from because your part of using clone() needs a check to see if the duplicate exist in the spot you are trying to add it to first before adding the duplicate so it knows not to add the duplicate if one already exist, that should fix the duplication issue.

1 Like

alright I’ll try to fix it using what you said

Alright I did what you said and moved my debounce if statement and that fixed 2/3 bugs that I know of so the last bug is the quest

if what i said fixed your issue you had originally, mark it as solved and make a new post related to your new issue which you say is the quest, you need a new post cause roblox doesn’t like it when you don’t lol and need more information to even help with that anyways if you even wanted me to help. if you did make a new post though i’ll take a look

1 Like

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