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

Weapon Giver Script Is Not Working? Help Please?

Asked by 9 years ago

The code below works properly, but if the player resets or dies, they're not able to receive the weapon again even if they step on the brick. I know why it doesn't work, and that's because I'm using the PlayerAdded event. The reason I'm posting this is because I only know how to make the script this way, and I know for a fact that it's possible to make the script without using PlayerAdded. So, let's cut to the chase:

game.Players.PlayerAdded:connect(function(player)

debounce = false

game.Workspace["Sword Giver Block"].Touched:connect(function(give)
if debounce == true then return end
debounce = false
game.Lighting.ClassicSword:Clone().Parent = player.Backpack
debounce = true
end)
end)

Is anyone willing to show me how to make it without using PlayerAdded?

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

It's simple really. Just take out line 01 and 11, then use the GetPlayerFromCharacter(character) method of Players.

debounce = false

game.Workspace["Sword Giver Block"].Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if debounce == true or player == nil then return end
    debounce = false
    game.Lighting.ClassicSword:Clone().Parent = player.Backpack
    debounce = true
end)
0
Thank you so much! alienantics 15 — 9y
Ad

Answer this question