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

Owner tool giver not working? [ANSWERED]

Asked by 10 years ago

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:

01game.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
11end)

I've also tried this, but still I got nothing.

01tool1 = game.ReplicatedStorage.Owner.Guided
02 
03game.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 tool1Clone = tool1:Clone()
08        owner:WaitForChild("Backpack")
09        tool1Clone.Parent = owner.Backpack
10    end
11end)

1 answer

Log in to vote
0
Answered by 10 years ago

Your second script is closer than the first. Let's dissect what's wrong.

This is our first issue.

1(ownercheck.Name == "Player"~= nil) then

You have randomly put a ~= nil there. Let's remove that.

01tool1 = game.ReplicatedStorage.Owner.Guided
02 
03game.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 tool1Clone = tool1:Clone()
09        tool1Clone.Parent = ownercheck.Backpack -- We have linked OwnerCheck to the player, so no need to go through the workspace.
10    end
11    end
12end)
Ad

Answer this question