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

Why isn't this simple script not working?

Asked by 9 years ago
game.Players.PlayerAdded:connect(function(plr)
    if plr.Name == "dragonmaster4111" or plr.Name == "Player" then
        k = game.ReplicatedStorage.Kill:Clone()
        k.Parent = game.Players.LocalPlayer.Backpack
    end
end)

It doesnt show any errors but the tool just wont get cloned into the backpack.

1
Is this a local script? You seem to be using '.LocalPlayer' even though you can use 'plr.Backpack' Necrorave 560 — 9y
0
it is a local script Operation_Meme 890 — 9y
1
Just curious. Have you tried using 'plr.Backpack' instead? I am not able to test this myself right now sadly. (At work) Necrorave 560 — 9y
0
let me try Operation_Meme 890 — 9y
0
Read my reply. Thetacah 712 — 9y

1 answer

Log in to vote
2
Answered by
Thetacah 712 Moderation Voter
9 years ago

last edits: Typos

Keep in mind that this sequence of code should be in a script and not in a localscript. I highly suggest you use :lower() and uncap the names. Read on lower() here. When using scripts you can't use 'game.Players.LocalPlayer.'. So, use the plr variable you created with your playeradded event.

game.Players.PlayerAdded:connect(function(plr)
    if plr.Name:lower() == "dragonmaster4111" or plr.Name:lower() == "player" then
        k = game.ReplicatedStorage.Kill:Clone()
        k.Parent = plr:FindFirstChild("Backpack")
    end
end)
0
Thanks Operation_Meme 890 — 9y
0
If you can summarize, why can't this be in a local script? Necrorave 560 — 9y
1
localscripts are scripts that run on the client instead of the server. PlayerAdded doesn't run in localscripts. Thetacah 712 — 9y
0
Ah, okay. I have always been iffy with localscripts. Thanks. Necrorave 560 — 9y
Ad

Answer this question