[solved now] need help with fixing the script inside seat to deal damage per second to player who sat on

hello there peoples in devforum, I have been having problem with making an script that is supposed to deal player who sat on a damage per second. and it uses bindableEvent functions for work, but however it does not work as intended yet.

I have used chatGPT and help from one other people from devforum, but it haven’t solved since. here is previous post I made that remains unsolved yet. the previous devforum post

also here is two script codes I’m currently using, this script belongs inside the seat.

--script inside seat that is supposed to fire an bindableEvent to damage player per second, and when player escape the seat, it is supposed to fire an another bindableEvent to stop dealing player damage per second.
local event = game.ServerStorage.PlayerDamagedPerSecond.Damage10PerSecondGrab
local stopevent = game.ServerStorage.PlayerDamagedPerSecond.StopDamage10PerSecondGrab
_G.timedamageonscreen = 4
cooldown = 14
DamageAmount = 11

debounce = true
script.Parent.Touched:Connect(function(plyr)
	if debounce == true then
		debounce = false
		local person = plyr.Parent
		if person:FindFirstChild("Humanoid") then
			person:FindFirstChild("Humanoid").Health = person.Humanoid.Health - DamageAmount
			local connection = script.Parent.Touched:Connect(function()
				event:Fire()
				if script.Parent.Occupant == false then
					stopevent:Fire()
					warn("Player escaped the grab, and stopevent that makes the grab stop damaging the player will fire.")
					debounce = true
					connection:Disconnect()
				end
			end)
		end
	end
end)

and this one is inside startercharacterscripts in my game, it also doesn’t work right now.

local event = game.ReplicatedStorage.PlayerDamagedPerSecond.Damage10PerSecondGrab
local stopevent = game.ReplicatedStorage.PlayerDamagedPerSecond.StopDamage10PerSecondGrab

local connection = event.Event:Connect(function()
	game.Players.LocalPlayer.Humanoid.Health -= 10
	wait(1)
	repeat wait(0.1) until stopevent.Event:Connect(function()
		connection:Disconnect()
	end)
end)

I don’t know if anyone will discover this topic, but I post this for get help from peoples. thank you so much. -mari

hey, is anyone reading this topic? I need help right now… -mari

Im not sure if this would work in different situations but I know it works simply.
You dont need 2 scripts for this.
This Is just one script that would go inside the seat :slight_smile:

local DamageAmount = 11
local connection = nil
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	
	if script.Parent.Occupant == nil then
		connection = nil
	end
	
	local character = script.Parent.Occupant.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	connection = true
	if character and player then
		while connection == true and wait(1) do
			local Humanoid = script.Parent.Occupant
			Humanoid:TakeDamage(DamageAmount)
		end
	end
end)

thank you so much for your help, now script is working as I wanted :hugs: -mari

1 Like

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