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

My fireball damage script isn't doing any damage?

So as the title implies, I'm trying to create a damage script for my fireball, however, when fired no damage is done to a humanoid. Here is my script:

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")~= nil then
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
		script.Parent:remove()
	end
end)

Respond ASAP, Thanks!

8 comments

0

first of all the remove function is deprecated in favor of :Destroy()

0

Do what he said ^. Also, is it a server script or local script? It needs to be a server script.

0

yea use the "TakeDamage()" Methed as using the "Health" Method changes the health at a "Strange eneral" for some reason.

0

@ItzFoxz It's a server script, thanks for the advice.

0

Do you have a RemoteEvent?

0

Also is it a tool or when pressing a key to fire it?

0

@fr2013 It dosen't have a remoteevent because I don't really have any exprience with using them, and its a key to fire.

0

Alright hold on

2 answers

Firstly, never use deprecated functions, read this to know more about deprecated functions and instances. Secondly you should use Humanoid:TakeDamage(20) as its more efficient and less messy then hit.Parent.Humanoid.Heath = hit.Parent.Humanoid.Health - 20.

Here is the fixed code (I tested this in studio so I know it works)

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")~= nil then
        hit.Parent.Humanoid:TakeDamage(20)
        script.Parent:Destroy()
    end
end)

3 comments

0

glad it could help.

0

Uhh, the code didn't work for me, output says "Touched is not a valid member of LocalScript"

0

Is it in a local script or server script?

First create a RemoteEvent in Workspace and name it "Fired" Then implement this in the script:

game.Workspace.Fired.OnServerEvent:Connect(function(Player) -- Finds the RemoteEvent
	local AlreadyTouched = false
	local Character = Player.Character or Player.CharacterAdded:wait() -- Finds a Player
	local Fireball = script.Parent -- Finds the Fireball you created 
	
	Fireball.Touched:Connect(function(Hit)
			local Humanoid = Hit.Parent:FindFirstChild("Humanoid") --Finds the Player that has "Humanoid"
			
			if Humanoid == nil then return end
			
			if AlreadyTouched == false then
				AlreadyTouched = true -- If it touches, then it'll activate this
				local debris = game:GetService("Debris")
					if Humanoid then 
						local creatorTag = Instance.new("ObjectValue") -- Creates a tag like a tool
						creatorTag.Value = Player
						creatorTag.Name = "creator"
						creatorTag.Parent = Humanoid
						debris:AddItem(creatorTag, 1)
					end;
				if Humanoid.Parent == Character then
					Humanoid.Health = Humanoid.Health - 0
				else
					Humanoid.Health = Humanoid.Health - Humanoid.MaxHealth/2 -- Change the damage
					Fireball:Destroy() -- If it hits the player, it'll disappear (You can delete this if you want to)
				end
			end
	end)
end)

3 comments

0

Also connect the RemoteEvent from workspace with the key you're pressing. If you need help doing that, then I'm happy to help.

0

@fr2013 can you help me fix the whole thing? I think its broken and I have no idea how to fix it, i tried your way and it still didn't know. Tell me if you want me to add you to teamcreate, thanks...

0

@T0BIUCHIHAA Alright add me in Team Create then

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