I need a script that do if you touch it it will generate random number from 1 to 10 and if the number will be 5 you will see the GUI.
Can somebody help me, please?
Thanks!
Vojtasuper2.
I need a script that do if you touch it it will generate random number from 1 to 10 and if the number will be 5 you will see the GUI.
Can somebody help me, please?
Thanks!
Vojtasuper2.
Vojtasuper2. What have you already tried to accomplish this? I think that a few quick google searches will give you all the answers.
A random number? math.random.
Setting text of UI? game.Players.LocalPlayer.ScreenGui.TextLabel.Text = "Text Here"
Touch detection? The Touched Event.
Put the together, and you get:
-- LocalScript:
workspace.Part.Touched:Connect(function(hit)
if not hit:IsDescendantOf(game.Players.LocalPlayer.Character) then return end
game.Players.LocalPlayer.ScreenGui.TextLabel.Text = math.random(1,10)
end)
-- Server Script:
workspace.Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit)
if not player then return end
player.ScreenGui.TextLabel.Text = math.random(1,10)
end)
Theres a few more parts that you might look up, but it’s a simple script.
blueberry.
local plr = game.Players.LocalPlayer
local Subject = script.Parent
local Min = 1
local Max = 10
Subject.Touched:Connect(function()
local RandomNumber = math.random(Min,Max)
if RandomNumber == 5 then
warn(RandomNumber)
plr.PlayerGui:WaitForChild("ScreenGui").Frame.Visible = true
else
print(RandomNumber)
plr.PlayerGui:WaitForChild("ScreenGui").Frame.Visible = false
end
end)
hmm, It doesn’t work for me.
can you try it in your studio and fix it?
Sorry, put this into StarterGui
local plr = game.Players.LocalPlayer
local Subject = workspace.Part -- Your Part
Subject.Touched:Connect(function()
local RN = math.random(1,10)
if RN == 5 then
plr.PlayerGui:WaitForChild("ScreenGui").Frame.Visible = true
else
plr.PlayerGui:WaitForChild("ScreenGui").Frame.Visible = false
end
end)
Make sure you add a Cooldown, it goes very fast