-
What do you want to achieve?
Make a SurfBoard! -
What is the issue?
I would like to have gravity on and reduce speed whenever the player is on Land, but make the surfboard actually work in the water, instead of the player just going to “swim” i guess… -
What solutions have you tried so far?
I have tried to raycast down from the Humanoid Root Position, but i don’t think it is working.
If people can point me in the right direction i’d be very thankful
SCRIPT
local Rep = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local physics = game:GetService("PhysicsService")
local player = Players.LocalPlayer
local char = player.Character
local root = char.HumanoidRootPart
local velocity = Vector3.zero
local bv = Instance.new("VectorForce", char.PrimaryPart)
bv.Force = velocity
bv.Name = "FlightForce"
local wPressed = false
local sPressed = false
local aPressed = false
local dPressed = false
uis.InputBegan:Connect(function(input, bool)
if input.KeyCode == Enum.KeyCode.F then --stops flying
Rep.Surf.RemoveSurfboard:FireServer()
local sound = player.Character.HumanoidRootPart:WaitForChild("Running", 10)
sound.Volume = 0.65
char.Animate.Disabled = false
bv:Destroy()
else
char.Animate.Disabled = true
local AnimationTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
-- Stop all playing animations
for i, track in pairs (AnimationTracks) do
track:Stop()
end
local sound = player.Character.HumanoidRootPart:WaitForChild("Running", 10)
sound.Volume = 0
end
if input.KeyCode == Enum.KeyCode.W then
wPressed = true
elseif input.KeyCode == Enum.KeyCode.S then
sPressed = true
elseif input.KeyCode == Enum.KeyCode.A then
aPressed = true
elseif input.KeyCode == Enum.KeyCode.D then
dPressed = true
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W then
wPressed = false
elseif key.KeyCode == Enum.KeyCode.S then
sPressed = false
elseif key.KeyCode == Enum.KeyCode.A then
aPressed = false
elseif key.KeyCode == Enum.KeyCode.D then
dPressed = false
end
end)
while wait() do
char.PrimaryPart:FindFirstChild("FlightForce").Force = Vector3.new(0,0,0)
local ray = Ray.new(root.Position,Vector3.new(0, -4, 0))
local hit, position, normal, material = workspace:FindPartOnRay(ray,char)
if material == Enum.Material.Water then
velocity = Vector3.new( root.CFrame.LookVector.X, 0.0 , root.CFrame.LookVector.Z)
else
velocity = Vector3.new( root.CFrame.LookVector.X, -1.0 , root.CFrame.LookVector.Z)
end
if wPressed then
local velocity = velocity * 1000
char.PrimaryPart:FindFirstChild("FlightForce").Force = velocity
end
if sPressed then
local velocity = velocity * -1000
char.PrimaryPart:FindFirstChild("FlightForce").Force = velocity
end
end