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

Character Is not a valid member of Player?

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

✓ Accepted answer

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)

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