Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[ANSWERED] Gui clones only on second attempt, Random math doesnt work, help ?

Asked by 4 years ago
Edited 4 years ago

So basically i am working on random loot crate, when you open it, it should copy a gui from itself (a model) and paste it into the player's playergui who clicked it, but for some reason, when i click it, it doesnt do anything on first time, second time I click it, it works but shows there both of the weapons even though there is random math that if it is under 50 then it is MP5 when it is above 50 it is M4A1, but it shows both of them for some reason or just the M4A1.

Doesn't give me any errors

math.randomseed(tick())

script.Parent.ClickDetector.MouseClick:connect(function(hit)


script.Parent.ClickDetector.MaxActivationDistance = 0
script.Parent.Parent.Sign.SurfaceGui.TextBox.Text = "Empty"
 script.Parent.Sound:Play()


local player = hit.Name
local random = math.random(1,100)


if random > 0 and random < 49 then
 local gun1 = script.Parent.Tier1LootCrate.Weapons.MP5
 gun1.Visible = true


elseif random > 50 and random < 100 then
 local gun2 = script.Parent.Tier1LootCrate.Weapons.M4A1
 gun2.Visible = true


wait(0.1)

local GUI = script.Parent.Tier1LootCrate:Clone()
GUI.Parent = game.Players[player].PlayerGui







end 

end)


1 answer

Log in to vote
0
Answered by 4 years ago

Alright, I figured it out myself! I moved the end from line 36 to line 23, now it works.

Ad

Answer this question