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

Why doesn't this OnSpawn Weapon Giver Script work?

Asked by 5 years ago
Edited 5 years ago

The script is supposed to check if the owner (me) is in the game and if I am, it gives me the gun. For some reason it doesn't work

if game.Players:FindFirstChild("SnakeInTheBoots") then
    gun.Parent = game.Players.SnakeInTheBoots:WaitForChild("Backpack")
end

0
and gun is defined by the way SnakeInTheBoots 54 — 5y
0
local gun = script.Parent.Parent.OwnerGun:Clone() SnakeInTheBoots 54 — 5y

1 answer

Log in to vote
0
Answered by
Rheines 661 Moderation Voter
5 years ago

To give yourself a weapon you need to connect a function when your player is added and when your character is added that gives you the item that you want. You also want to clone the weapon after your character has respawned.

--The player service.
local PlayerService = game:GetService("Players")

--This is the location of the gun, preferably put it in ServerStorage.
local gun =

--Connect a function when the player is added.
game.Players.PlayerAdded:Connect(function(player)

    --Connect a function when the character is added everytime they spawn.
    plr.CharacterAdded:Connect(function(char)
        if char.Name == "SnakeInTheBoots" then
            local cloned = gun:Clone()
            cloned.Parent = PlayerService.SnakeInTheBoots:WaitForChild("Backpack")
        end
    end)
end)
0
thanks man SnakeInTheBoots 54 — 5y
Ad

Answer this question