made a gui that is supposed to award a gun from lighting when clicked but when i click nothing happens. what did i do wrong?
local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onClick() local human = workspace:findFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local player = getPlayer(human) if (player == nil) then return end local x = game.Lighting.gun:Clone() x.Parent = player.Backpack wait(2) debounce = false end end script.Parent.MouseButton1Click:connect(onClick)
You should not be using lighting to store objects anymore use ServerStorage Click Here
This script was ran from:- StarterGui-->ScreenGui-->Frame-->TextButton
local debounce = true function onClick() if debounce then -- an if statement must be true to run debounce = false local plr = script.Parent.Parent.Parent.Parent.Parent.Name -- gets player name, You msy need to change this depending upon where the script is running local Gplr = game.Players:FindFirstChild(plr) --finds player in the game if Gplr ~= nil then local x = game.ServerStorage.gun:Clone() -- Use server storage. Clones gun x.Parent = Gplr.Backpack -- gives player the gun wait(2) debounce = true end end end script.Parent.MouseButton1Click:connect(function() onClick() end)
Hope it helps, let me know if you get any errors