-
I want that part of the script in the waterbike to get the player’s ‘isRiding’ value which determines whether he is currently riding on a vehicle or not.
-
it works at the beginning of the game and works when I delete and put new bikes for the new round. After a couple of rounds, it gives me the error
Workspace.waterbike.Script:18: attempt to index nil with ‘isRiding’
- I have tried putting waitforchild but it gives an infinite yield.
here is one of the waterbike scripts. There is a lot of water bikes in the game and after 1 round of racing with them, I delete and respawn new waterbikes.
local anim2 = script.Parent.fanANimation
local Humanoid = script.Parent.Humanoid
local animator = Humanoid.Animator
local hmr = script.Parent.HumanoidRootPart
local anim = animator:LoadAnimation(anim2)
local ridingAnim = script.Parent.ridingAnimation
local touchAllowed = Instance.new("BoolValue")
touchAllowed.Parent = script.Parent
local remote = game.ReplicatedStorage.remotes.bikeRemote
touchAllowed.Value = true
hmr.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if touchAllowed.Value == true then
if humanoid then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
print(plr)
isRiding = plr.isRiding
canTouchFinishLine = plr.canTouchFinishLine
anim:Play()
isRiding.Value = "waterBike"
touchAllowed.Value = false
local humr = hit.Parent:FindFirstChild("HumanoidRootPart")
humr.CFrame = script.Parent.weldingPos.CFrame
local weld = Instance.new("Weld")
weld.Parent = script.Parent.sit
weld.Part0 = humr
weld.Part1 = script.Parent.weldingPos
ridingonahorse = humanoid:LoadAnimation(ridingAnim)
ridingonahorse:Play()
end
end
end
end)
remote.OnServerEvent:Connect(function()
isRiding.Value = "false"
canTouchFinishLine.Value = true
game.Workspace.waterBike.sit.Weld:Destroy()
ridingonahorse:Stop()
wait(2)
touchAllowed.Value = true
print("put stuff false for")
end)