Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't this simple script not working?

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.

5 comments

1

Is this a local script? You seem to be using '.LocalPlayer' even though you can use 'plr.Backpack'

0

it is a local script

1

Just curious. Have you tried using 'plr.Backpack' instead? I am not able to test this myself right now sadly. (At work)

0

let me try

0

Read my reply.

1 answer

✓ Accepted answer

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)

4 comments

0

Thanks

0

If you can summarize, why can't this be in a local script?

1

localscripts are scripts that run on the client instead of the server. PlayerAdded doesn't run in localscripts.

0

Ah, okay. I have always been iffy with localscripts. Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.