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

Why doesn't the dagger clone properly into the player when they join?

Asked by 4 years ago
local function onCharacterAdded(character)
    if game.Workspace.Trueorno.Value >= 1 then
        local plr = game.Players:GetPlayerFromCharacter(character)
        local dagger = game.ReplicatedStorage.DaggerWood:Clone()
        dagger.Parent = plr.Backpack
    end
end

This script is supposed to clone a Wooden Dagger into the player's backpack each time they respawn, but it never does. It's only supposed to happen when the lobby doesn't exist, which is why I made the if statement. There are no errors, so I'm not sure what's wrong with it. If you know what is, please help by posting a comment or answer. Thanks.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

you never called the function that is why it is not running. Also, change it to this :

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        if game.Workspace.Trueorno.Value >= 1 then
            local dagger = game.ReplicatedStorage.DaggerWood:Clone()
            dagger.Parent = plr.Backpack
        end
    end)
end
0
I don't want it to be PlayerAdded, as Character is different. It should be whenever the player respawns, and not joining. Trisodin529 89 — 4y
0
I think the problem is that it always goes through the if statement. Trisodin529 89 — 4y
0
ok, let me change this then BrainDead_Dev 135 — 4y
0
ok, let me change this then BrainDead_Dev 135 — 4y
View all comments (7 more)
0
Edited! should work now BrainDead_Dev 135 — 4y
0
Thanks! Honestly thought it wouldn't work, but it did after fixing an error (changed the last end to end) to close the function) Trisodin529 89 — 4y
0
Thanks! Honestly thought it wouldn't work, but it did after fixing an error (changed the last end to end) to close the function) Trisodin529 89 — 4y
0
Thanks! Honestly thought it wouldn't work, but it did after fixing an error (changed the last end to end) to close the function) Trisodin529 89 — 4y
0
Thanks! Honestly thought it wouldn't work, but it did after fixing an error (changed the last end to end) to close the function) Trisodin529 89 — 4y
0
ok, glad I could help BrainDead_Dev 135 — 4y
0
Not sure why that same comment got posted 4 times :/ Trisodin529 89 — 4y
Ad

Answer this question