How to make this part cause damage to the player ? (video + script)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Hello, as you can see on the video I created a small challenge with stones falling from the sky and the players must avoid them. Except that I tried everything I can’t manage to make sure that when the stone touches the player he loses life. Can you help me please

Video:


Script:

function rock()
	local rock = RS.Rock:Clone()
	rock.Position = Vector3.new(math.random(-936.8,-774.619), 110.577, math.random(-22582.9, -22451.279))
	rock.Size = Vector3.new(math.random(7.475, 26.394), 0.077, math.random(10.12, 37.905))
	rock.Color = Color3.fromRGB(225, 10, 13)
	rock.CanTouch = false
	rock.Parent = workspace
	local rock2 = RS.Rock:Clone()
	rock2.Anchored = false
	rock2.CanTouch = true
	rock2.Position = rock.Position + Vector3.new(0,300,0)
	rock2.Size = rock.Size + Vector3.new(0,math.random(7, 20),0)
	rock2.Parent = workspace
	local rock3 = RS.Rock:Clone()
	rock3.Position = Vector3.new(math.random(-936.8,-774.619), 110.577, math.random(-22582.9, -22451.279))
	rock3.Size = Vector3.new(math.random(7.475, 26.394), 0.077, math.random(10.12, 37.905))
	rock3.Color = Color3.fromRGB(225, 10, 13)
	rock3.CanTouch = false
	rock3.Parent = workspace
	local rock4 = RS.Rock:Clone()
	rock4.Anchored = false
	rock4.CanTouch = true
	rock4.Position = rock3.Position + Vector3.new(0,300,0)
	rock4.Size = rock3.Size + Vector3.new(0,math.random(7, 20),0)
	rock4.Parent = workspace
	wait(6)
	rock:Destroy()
	rock2:Destroy()
	rock3:Destroy()
	rock4:Destroy()
end

workspace.Halloween.Part4.Start.Touched:Connect(function(hit)
	if hit.Parent.Name == plr.Name then
		workspace.Halloween.Part4.Start.CanTouch = false
		connection3:Disconnect()
		connection2 = RunS.RenderStepped:Connect(function(dt)
			total_time += dt
			if total_time > time_wait_before_loop then
				total_time = 0
				rock()
			end
		end)
	end
end)

Photo:

Please if someone has a solution it would be really great. I precise that the rock script i’ve send is a client sided script

you should probably use debounce

local debounce = false
--touch event here
if not debounce then
--damage script here
end
end)

Also check if the rock has CanTouch enabled

Doesn’t work, and yes touched event is activated of course. This make me crazy i don’t understand why it doesn’t work

1 Like

I specify also that if I put the part in the workspace with the server script insde, the part can kill me. But when it is cloned the action of the script does not work

Seeing your output I realize that the script that clones the rocks is localside, try to clone them in a server script

Maybe only the cloning part can be done serverside via RemoteEvent

Working solution by @OrderDestroy

function rock()
	local rock = RS.Rock:Clone()
	rock.Position = Vector3.new(math.random(-936.8,-774.619), 110.577, math.random(-22582.9, -22451.279))
	rock.Size = Vector3.new(math.random(7.475, 26.394), 0.077, math.random(10.12, 37.905))
	rock.Color = Color3.fromRGB(225, 10, 13)
	rock.CanTouch = false
	rock.Parent = workspace
	local rock2 = RS.Rock:Clone()
	rock2.Anchored = false
	rock2.CanTouch = true
	rock2.Position = rock.Position + Vector3.new(0,300,0)
	rock2.Size = rock.Size + Vector3.new(0,math.random(7, 20),0)
	rock2.Parent = workspace
	local rock3 = RS.Rock:Clone()
	rock3.Position = Vector3.new(math.random(-936.8,-774.619), 110.577, math.random(-22582.9, -22451.279))
	rock3.Size = Vector3.new(math.random(7.475, 26.394), 0.077, math.random(10.12, 37.905))
	rock3.Color = Color3.fromRGB(225, 10, 13)
	rock3.CanTouch = false
	rock3.Parent = workspace
	local rock4 = RS.Rock:Clone()
	rock4.Anchored = false
	rock4.CanTouch = true
	rock4.Position = rock3.Position + Vector3.new(0,300,0)
	rock4.Size = rock3.Size + Vector3.new(0,math.random(7, 20),0)
	rock4.Parent = workspace
        local c1,c2
        c1 = rock2.Touched:Connect(function(t)
          if t.Parent == game.Players.LocalPlayer.Character then
            game.Players.LocalPlayer.Character.Humanoid.Health-=20
            c1:Disconnect()
          end
        end)
        c2 = rock4.Touched:Connect(function(t)
          if t.Parent == game.Players.LocalPlayer.Character then
            game.Players.LocalPlayer.Character.Humanoid.Health-=20
            c2:Disconnect()
          end
        end)
	wait(6)
	rock:Destroy()
	rock2:Destroy()
	rock3:Destroy()
	rock4:Destroy()
end

workspace.Halloween.Part4.Start.Touched:Connect(function(hit)
	if hit.Parent.Name == plr.Name then
		workspace.Halloween.Part4.Start.CanTouch = false
		connection3:Disconnect()
		connection2 = RunS.RenderStepped:Connect(function(dt)
			total_time += dt
			if total_time > time_wait_before_loop then
				total_time = 0
				rock()
			end
		end)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.