Untitled
unknown
plain_text
2 years ago
3.3 kB
10
Indexable
local e = true
local function ifdead()
script.Parent.Humanoid.Died:Connect(function()
e = false
workspace.Gravity = 196.2
script:Destroy()
end)
end
local function fireLaser()
local rayOrigin = script.Parent.Head.Position
local rayDirection = Vector3.new(0, -100, 0)
-- Build a "RaycastParams" object and cast the ray
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
-- Check if the part resides in a folder, that it's fully visible, and not locked
if hitPart.Parent == workspace and hitPart.Name == "Sand"then
local underwater = true
wait(.2)
local char = game.Players.LocalPlayer.Character
local root = char:WaitForChild'HumanoidRootPart'
local hum = char.Humanoid
local runservice = game:GetService'RunService'
local uis = game:GetService'UserInputService'
local waterline = workspace.Wave:WaitForChild('Plane')
local bodyforce_name = 'water BodyForce'
local tweenservice = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local velocity_fade = tweenservice:Create(root,tweenInfo,{Velocity = Vector3.new()})
local time_entered_water = tick()
local time_left_water = tick()
runservice.Stepped:Connect(function()
if root.Position.y < waterline.Position.y - 3.1 then
if not underwater then --when you first enter the water
underwater = true
time_entered_water = tick()
root.Velocity = root.Velocity * .1
end
if tick() - time_left_water > .5 then --prevents weird constant state changing when near surface
hum:ChangeState("Swimming")
end
workspace.Gravity = 0
hum:SetStateEnabled('Running',false)
hum:SetStateEnabled('RunningNoPhysics',false)
hum:SetStateEnabled('Climbing',false)
hum:SetStateEnabled('GettingUp',false)
hum:SetStateEnabled('Jumping',false)
local moving = hum.MoveDirection ~= Vector3.new()
local trying_to_rise = uis:IsKeyDown(Enum.KeyCode.Space) --consider mobile jump button gui & controller's ButtonA
if not moving and not trying_to_rise and tick() - time_entered_water > .2 then
velocity_fade:Play()
else
velocity_fade:Cancel()
end
else
if underwater then
underwater = false
print("")
time_left_water = tick()
workspace.Gravity = 196.2
hum:SetStateEnabled('Running',true)
hum:SetStateEnabled('RunningNoPhysics',true)
hum:SetStateEnabled('Climbing',true)
hum:SetStateEnabled('GettingUp',true)
hum:SetStateEnabled('Jumping',true)
end
end
end)
end
end
end
while wait(0.1) do
if e == true then
fireLaser()
end
end
Editor is loading...