Hi, I am developing a boat and have also finished it however I have this bug where if I leave the boat still holding keys that make it move(w,a,s,d) then is will continue to move even tho I remove the script that lets the player control the boat and I removed it permissions, so I tried to reset the values (vector force and the motor thing inside of cylindrical constraint) but it still wont reset I even made it so that the script that resets the values would have to wait for the script that is sent to the player but that just errors because I already deleted it before I check. any help would be appreciated
robloxapp-20210329-1931303.wmv (6.0
local VehicleSeat = script.Parent
local _lastPlayer
VehicleSeat.Changed:Connect(function(prop)
if prop == "Occupant" then
local humanoid = VehicleSeat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player then
VehicleSeat:SetNetworkOwner(player)
_lastPlayer = player.Name
script.Parent.Parent.Name = player.Name.." Boat"
local playerScript = script.Parent.BoatScript:Clone()
playerScript.Parent = game.Players[tostring(player.Name)].Backpack
end
else
if game.Players[_lastPlayer].Backpack.BoatScript then
game.Players[_lastPlayer].Backpack.BoatScript:Destroy()
end
script.Parent.Parent.Tail.CylindricalConstraint.TargetAngle = 0 -- not working note sure why
script.Parent.Parent.Tail.VectorForce.Force = Vector3.new(0,0,0)-- not working not sure why
print("should be reset?")
VehicleSeat:SetNetworkOwnershipAuto()
end
end
end)
local script
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local _boat = game.Workspace[script.Parent.Parent.Name.." Boat"]
local _forward
local _backword
local _left
local _right
UserInputService.InputBegan:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.Keyboard then -- check if input was from keyboard
local value = inputObject.KeyCode -- the value of the enum
if value == Enum.KeyCode.W then
_forward = true
end
if value == Enum.KeyCode.S then
_backword = true
end
if value == Enum.KeyCode.A then
_left = true
end
if value == Enum.KeyCode.D then
_right = true
end
end
end)
UserInputService.InputEnded:Connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.Keyboard then -- check if input was from keyboard
local value = inputObject.KeyCode -- the value of the enum
if value == Enum.KeyCode.W then
_forward = false
end
if value == Enum.KeyCode.S then
_backword = false
end
if value == Enum.KeyCode.A then
_left = false
end
if value == Enum.KeyCode.D then
_right = false
end
end
end)
RunService.Stepped:Connect(function()
if _forward == true then
_boat.Tail.VectorForce.Force = Vector3.new(-5000,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
elseif _backword == true then
_boat.Tail.VectorForce.Force = Vector3.new(5000,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
else
_boat.Tail.VectorForce.Force = Vector3.new(0,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
end
if _left == true then
_boat.Tail.CylindricalConstraint.TargetAngle = 10
elseif _right == true then
_boat.Tail.CylindricalConstraint.TargetAngle = -10
else
_boat.Tail.CylindricalConstraint.TargetAngle = 0
end
end)
Exlporer
MB)