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

Character Is not a valid member of Player?

Asked by 2 years ago

It sends a error that says Character is not a valid member of Player? Code:

local Mouse = game:GetService("Players").LocalPlayer:GetMouse() local Audio = Instance.new("Sound") Sound.Parent = player.Character Sound.SoundId = "9858343944" Mouse.KeyDown:Connect(function(Key) if Key == "W" then Mouse.KeyDown:Connect(playsound) Sound:Play() Mouse.KeyUp:Connect(stopsound) Sound:Stop() end end)

1 answer

Log in to vote
0
Answered by 2 years ago

Hello,

if you are accessing the player from workspace than you don't need player.Character you can just parent the Audio to the Player directly.

if it still doesn't work, what you can do is

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()

local Audio = Instance.new("Sound")
    Audio.Parent = Plr
    Audio.SoundId = "9858343944"

Mouse.KeyDown:Connect(function(Key)
     if Key == "W" then
        Sound:Play()
        playsound()
    end
end)

Mouse.KeyUp:Connect(function(Key)
    if Key == "W" then
        Sound:Stop()
        stopsound()
    end
end)
Ad

Answer this question