I'm trying to make a script so that when the game owner enters the game, they are given a unique tool located in ReplicatedStorage. I'm no expert on scripting, but I know some of the basics. I've been trying to come up with a script, but nothing works. This is what I already have:
01 | game.Players.PlayerAdded:connect( function (check) |
02 | if check:FindFirstChild( "Humanoid" ) then |
03 | if check.Name = = "Player" then |
04 | local player = game.Players:GetPlayerFromCharacter(check) |
05 | if player ~ = nil then |
06 | local tool = game.ReplicatedStorage.TOOLNAME:Clone() |
07 | tool.Parent = player.Backpack |
08 | end |
09 | end |
10 | end |
11 | end ) |
I've also tried this, but still I got nothing.
01 | tool 1 = game.ReplicatedStorage.Owner.Guided |
02 |
03 | game.Players.PlayerAdded:connect( function (ownercheck) |
04 | if (ownercheck.Name = = "Player" ~ = nil ) then |
05 | game.Workspace:WaitForChild( "Player" ) |
06 | local owner = game.Workspace.Player |
07 | local tool 1 Clone = tool 1 :Clone() |
08 | owner:WaitForChild( "Backpack" ) |
09 | tool 1 Clone.Parent = owner.Backpack |
10 | end |
11 | end ) |
Your second script is closer than the first. Let's dissect what's wrong.
1 | (ownercheck.Name = = "Player" ~ = nil ) then |
You have randomly put a
~= nil
there. Let's remove that.
01 | tool 1 = game.ReplicatedStorage.Owner.Guided |
02 |
03 | game.Players.PlayerAdded:connect( function (ownercheck) |
04 | if (ownercheck.Name = = "NAME HERE" ) then |
05 | game.Workspace:WaitForChild( "NAME HERE" ) |
06 | local owner = game.Workspace [ "NAME HERE" ] |
07 | if owner then -- I added this myself, to make sure the owner actually exists. |
08 | local tool 1 Clone = tool 1 :Clone() |
09 | tool 1 Clone.Parent = ownercheck.Backpack -- We have linked OwnerCheck to the player, so no need to go through the workspace. |
10 | end |
11 | end |
12 | end ) |