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

Why the touched event takes some time to occur?

I am coding a fire ball but it should explode on direct contact with a dummy or a player but sometimes it the touched event doesn't run and other times it runs but after a delay of like 0.5 seconds. here is the code:

local damage = 40
local TweenService = game:GetService("TweenService")
script.Parent.Touched:connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") and script.Parent.Value.Value~=h.Parent.Name and script.Parent:FindFirstChild(h.Parent.Name) == nil then
		h.Parent.Humanoid:TakeDamage(damage)
		print("hit and damaged"..h.Parent.Name)
		local firsthit = Instance.new("StringValue")
		firsthit.Name = h.Parent.Name
		firsthit.Parent = script.Parent
		script.Parent.Anchored = true
		damage = 15
		local tweeninfo = TweenInfo.new(
			0.5,
			Enum.EasingStyle.Quad,
			Enum.EasingDirection.Out,
			0,
			false
		)
		
		local partprop = {
			Size = Vector3.new(10,10,10);
			Transparency = 1;
		}
		local tween = TweenService:Create(script.Parent,tweeninfo,partprop)
		tween:Play()
		script.Parent.ParticleEmitter.Enabled = false
		wait(0.5)
		for i,v in pairs(script.Parent:GetTouchingParts()) do
			if script.Parent.Value.Value ~= v.Parent.Name and v.Name ~= script.Parent.Value.Value and script.Parent:FindFirstChild(v.Parent.Name) == nil and v.Parent:FindFirstChild("Humanoid") ~= nil then
			v.Parent.Humanoid:TakeDamage(damage)
			local thing = Instance.new("StringValue")
			thing.Name = v.Parent.Name
			thing.Parent = script.Parent
			print("damaged"..v.Parent.Name)
			end
		end
	else
		print("The player hit himself")
	end
end)

1 comment

0

Profane language is not permitted on our website. Please review our Community Guidelines https://scriptinghelpers.org/help/community-guidelines

1 answer

Delays happens like 90% all the time when using .Touched event, I'm here just to tell you the facts. If you need to know how to prevent this, search it up on the wiki about lag and performance.

2 comments

0

if i added fireserver() in an event will it work?

0

if i added fireserver() in an event will it work?

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