so im wanting to use math.random
to print a number onto a TextLabel when u click a brick, but ive got very very little Lua knowledge so idk how to do this :/ all i know how to do it print it to the output
So this is a 55x2 Dice roll Gambling system
This is its simple form, ill be making it a full GUI later but in simple form you Click the brick, it rolls math.random 1-100 if its 55 or higher it adds X to gold.....ive got the rolling and the 55+ adding to gold but i need the number that it rolls to show up in a TextLabel, which i dont know how to do
I tried
Dice.Text = Rolls
But i guess i dont know enough because it didnt work :/
heres my code :)
function onTouched(clicked) part = clicked.Character.Head local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("leaderstats") if (stats~=nil) then local score = stats:findFirstChild("Gold") if (score~=nil) then local Dice = game.StarterGui.HUD.Roll -- This is the TextLabel local Rolls = math.random(100) for _ = 1, 1 do print(Rolls) if Rolls >= 55 then --This is being used as a 55x2 Gambling system score.Value = score.Value + 1 end wait(.1) end end end end end end script.Parent.ClickDetector.MouseClick:connect(onTouched)
Alright so basically, You're trying to changing the Starter gui NOT the player gui, Soooo, When you reset, then it will change.
Now fixing this is sorta simple, ish.
What we should do is put this script into a local script, And have it inside of the gui, Because of the script being a local script you can get the player you're trying to change from the players for example:
game.Players.LocalPlayer
This is the final product:
function onTouched(clicked) part = clicked.Character.Head local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("leaderstats") if (stats~=nil) then local score = stats:findFirstChild("Gold") if (score~=nil) then local Dice = game.Players.LocalPlayer.PlayerGui.HUD.Roll local Rolls = math.random(100) dice.Text = Rolls for _ = 1, 1 do print(Rolls) if Rolls >= 55 then score.Value = score.Value + 1 end wait(.1) end end end end end end script.Parent.ClickDetector.MouseClick:connect(onTouched)
Obviously there are some other things wrong but this is the one I saw