game.Players.PlayerAdded:Connect(function(player)
local car = workspace(player.Name.."Car")
function onClicked()
car.DriveSeat.HN.Volume = 0
end
end)
script.Parent.ClickDetector.MouseClick:connect(onClicked)
I am using the script in a serverscript not a localscript
Comes back as nil
I want to get the car by doing the players name then the name “Car”
Please help fast
I think the reason why it shows up as “nil” is because you aren’t referencing the car in workspace.
I’m not sure about this yet, but, Try Finding the car with FindFirstChild.
game.Players.PlayerAdded:Connect(function(player)
local car = workspace:FindFirstChild(player.Name.."Car") -- or you could use a better prefix: player.Name.." Car" -- use this if your car has a space between the player's name.
function onClicked()
car.DriveSeat.HN.Volume = 0
end
end)
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Thank you all for replying but I just found another solution! Thanks for your help. If you see a error in this you can still help by solving the script error. Thanks!
You’re getting that error because onClikcked function does not exit. Here fixed it.
function onClicked(plr)
local car = workspace:FindFirstChild(plr.Name.."Car")
car.DriveSeat.HN.Volume = 0
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)