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?
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)
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)