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

NPC removing values to a IntValue not working?

Hello! I wanted to make a script where a NPC approaches this gate and then once touched it, the NPC will start dealing some damage to it. Damage represented by a IntValue. I used a RemoteEvent.

--LOCAL SCRIPT PUT IN THE GATE (PART PUT IN WORKSPACE)
script.Parent.Touched:Connect(function(db)
       local hum = db.Parent:WaitForChild("Humanoid")
	if hum then
		game.ReplicatedStorage.GATE:FireServer()
	end
end)

--SCRIPT PUT IN THE NPC 
local zombie = script.Parent
local humanoid = zombie.Humanoid
 
local pointA = game.Workspace.DGATE.Humanoid
 
humanoid:MoveTo(pointA.Position)

game.ReplicatedStorage.GATE.OnServerEvent:Connect(function()
	print("Received")
	while wait(3) do
    pointA.Health:Damage(15)
 end
end)

Please help!

EDIT. I tried modifying some things. It is not working at all. It like doesn't notice I touch the part. I tried inserting a "print" after the Touched event. No signs. Why?

3 comments

0

why would you have local script in gate?

0

@karlo_tr10 Because I couldn't do the "FireServer".

0

I think you should put your gate script into normal script(server script)

3 answers

First of all script inside the gate should be server script and because of that you can't do FireServer(),so you can replace that part from npc to hate script and also make sure to break the loop once its destroyed/killed

Try changing the touched function to something like this:

script.Parent.Touched:Connect(function(db)
	if db.Parent:FindFirstChild("Humanoid") then
		print("touched") -- you can remove this once you confirm that it works
		game.ReplicatedStorage.GATE:FireServer()
	end
end)

2 comments

0

Still not working. :/

0

If this is not working then you are doing something wrong or script is disabled

Try putting your gate script inside serverscript instead of local script since this script doesn't have to involve player interaction.

Also, for your npc script you defined pointA as humanoid.Position, which won't work. Instead, try doing

local pointA = workspace.DGATE.HumanoidRootPart

humanoid:MoveTo(pointA.Position)

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