Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't this OnSpawn Weapon Giver Script work?

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

2 comments

0

and gun is defined by the way

0

local gun = script.Parent.Parent.OwnerGun:Clone()

1 answer

✓ Accepted answer

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)

1 comment

0

thanks man

This discussion is preserved as it was. New answers, comments, and votes are closed.