Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To Deal Damage Once To A Player(FE)?

How would I deal damage to a player when they are touched by a block, but only deal that damage once to that player while they are touching it and then if another player comes and touches the block then they only take the damage once, etc. I'm trying to make an attack that makes a giant "pool" all around them and then if a player touches it they take damage once and if a player walks into it, then they take the damage once. Any help? Also if anyone knows how to make a weapon equip from a script and not a tool then could you please go check out my previous post as well? Thanks.

1 answer

try this:


--Server Script (Normal script)

local brick = script.Parent
local tbl= {}
local dmg = 50

brick.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local found = false
	for _,v in pairs(tbl) do
		if v == player.Name then
			found = true
		end
	end
	if not found then
		player.Character.Humanoid:TakeDamage(dmg)
		tbl[#tbl+1] = player.Name
	end
end)

3 comments

0

use table.insert(), other than that it looks pretty gud

0

where exactly would i use table.insert?

0

well, you can replace line 17 using table.insert(tbl,#tbl+1,player.Name)

This discussion is preserved as it was. New answers, comments, and votes are closed.