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

Unable to Destroy()?

Asked by
TofuBytes 500 Moderation Voter
10 years ago

I'm trying to figure out what's wrong with my script and why it's not removing the sound script as well as not changing the walkspeed within the Player after they respawn. Any help?

function onPlayerEntered(player)
    repeat wait () until player.Character ~= nil
    Player.Character.Sound:Destroy()
    Player.Character.Humanoid.WalkSpeed = 5
    player.CharacterAdded:connect(function (char)
        Player.Character.Sound:Destroy()
        Player.Character.Humanoid.WalkSpeed = 5     
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

4 answers

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
10 years ago
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function (char)
        char:WaitForChild("Sound"):Destroy()
           char:WaitForChild("Humanoid").WalkSpeed = 5 
end)
end)

This should work your script probably broke and ran to early.

Ad
Log in to vote
0
Answered by 10 years ago

Your 6th and 7th line "players" are capitalized, try that?

Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
10 years ago
function onPlayerEntered(player)
    repeat wait () until player.Character ~= nil
    Player.Character.Sound:Destroy()
    Player.Character.Humanoid.WalkSpeed = 5
    Player.CharacterAdded:connect(function (char) -- you had 'player' not 'Player'
        Player.Character.Sound:Destroy()
        Player.Character.Humanoid.WalkSpeed = 5     
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

This should work now.

Log in to vote
-2
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
10 years ago

The first time a player joins, it removes the sound, then after that, it removes it again when the character joins the workspace. you just got to remove lines 3 and 4.

0
But when the player respawns the sound comes back again. TofuBytes 500 — 10y

Answer this question