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

Gui not giving tool?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

The script would give the player the tool once clicked and teleports player while removing the gui. The error is Player is not a valid member of Players The player will teleport, but the tool won't be given? Help?

Toolname = "Snowball" -- Tool Name
Players = game:GetService("Players")
spawns = game.Workspace.Spawning:GetChildren() -- Get spawns
function onClicked()
    script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(spawns[math.random(1,#spawns)].Position) -- teleports players randomly
script.Parent:Destroy()
if not Players.Player.Backpack:FindFirstChild(Toolname) then -- if player has tool then it won't give
        local Tool = game.ReplicatedStorage[Toolname]:clone()  -- player doesn't have it'll give the tool
        Tool.Parent = Players.Player.Backpack -- clones tool here
    end
end

script.Parent.MouseButton1Down:connect(onClicked)

Answer this question