Honestly, I assume you’re using a Server Script. Using a server script makes this way too complicated. You’d be better off using a local script or a script with the RunContext
Client.
You can try using this code in a script with RunContext
Client under the SizePart.
Code
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local SizePart = script.Parent :: BasePart
local TouchPart = workspace.LavaRisePart
local SurfaceLight = SizePart.SurfaceLight2
local sound = Instance.new("Sound") -- create the sound.
sound.SoundId = "rbxassetid://11855956184"
sound.Parent = workspace
local debounce = false
local TweenInformation = TweenInfo.new(
350,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local partProperties = {Size = Vector3.new(2048, 4000, 2048)}
local theTweenofalltime = TweenService:Create(SizePart, TweenInformation, partProperties)
LocalPlayer.CharacterRemoving:Connect(function() -- Will revert these once the local player dies.
-- you can put anything here that you want to reset once the player dies
theTweenofalltime:Cancel()
SurfaceLight.Enabled = false
SizePart.Color = Color3.fromRGB(86, 36, 36)
sound:Stop()
end)
TouchPart.Touched:Connect(function(part: BasePart)
local isLocalPlayer = part.Parent ~= nil and Players:GetPlayerFromCharacter(part.Parent) == LocalPlayer
if isLocalPlayer and part.Parent:FindFirstChild("Humanoid") ~= nil and debounce ~= true then -- When the player is the local player and it has a humanoid, then the tween can start playing.
debounce = true
sound:Play()
task.wait(10.3)
if part.Parent:FindFirstChild("Humanoid") == nil and part.Parent.Humanoid.Health <= 0 then -- If now the player's character doesn't exist anymore or the player's health is below than zero, then it will not play the tween.
print("Will not play the tween!")
return
end
print("Humanoid exists, will play the tween")
-- you can put anything here that you want to play.
theTweenofalltime:Play()
SizePart.Color = Color3.fromRGB(255, 89, 89)
SurfaceLight.Enabled = true
task.wait(2)
debounce = false
end
end)
You may say like, because you can’t deal damage or apply a certain health to humanoids on client, how do you deal damage to the player when touching the player. You can do this:
DamageCode
put this line somewhere that looks fitting
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("LavaDamage") -- wait for the remote event to be created.
then you can put these lines under the TouchPart
event
SizePart.Touched:Connect(function(p)
local plr: Player = p.Parent ~= nil and Players:GetPlayerFromCharacter(p.Parent)
if plr ~= LocalPlayer then
return
end
RemoteEvent:FireServer()
end)
now create a script in ServerScriptService. you can name it whatever you want.
paste this code in:
local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Name = "LavaDamage"
RemoteEvent.Parent = game:GetService("ReplicatedStorage")
local playerDebounce = {}
RemoteEvent.OnServerEvent:Connect(function(plr)
if playerDebounce[plr] then
return
end
playerDebounce[plr] = true
if plr.Character ~= nil and plr.Character:FindFirstChild("Humanoid") ~= nil then
plr.Character.Humanoid.Health -= 101 -- put whatever damage you want for the player to be dealt.
end
task.wait(.05)
playerDebounce[plr] = nil
end)
and damaging the player should work now