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 9 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:

game.Players.PlayerAdded:connect(function(check)
    if check:FindFirstChild("Humanoid") then
        if check.Name == "Player" then
            local player = game.Players:GetPlayerFromCharacter(check)
            if player ~= nil then
                local tool = game.ReplicatedStorage.TOOLNAME:Clone()
                tool.Parent = player.Backpack
            end
        end
    end
end)

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

tool1 = game.ReplicatedStorage.Owner.Guided

game.Players.PlayerAdded:connect(function(ownercheck)
    if (ownercheck.Name == "Player"~= nil) then
        game.Workspace:WaitForChild("Player")
        local owner = game.Workspace.Player
        local tool1Clone = tool1:Clone()
        owner:WaitForChild("Backpack")
        tool1Clone.Parent = owner.Backpack
    end
end)

1 answer

Log in to vote
0
Answered by 9 years ago

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

This is our first issue.

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

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

tool1 = game.ReplicatedStorage.Owner.Guided

game.Players.PlayerAdded:connect(function(ownercheck)
    if (ownercheck.Name == "NAME HERE") then
        game.Workspace:WaitForChild("NAME HERE")
        local owner = game.Workspace["NAME HERE"]
    if owner then -- I added this myself, to make sure the owner actually exists.
        local tool1Clone = tool1:Clone()
        tool1Clone.Parent = ownercheck.Backpack -- We have linked OwnerCheck to the player, so no need to go through the workspace.
    end
    end
end)
Ad

Answer this question