Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NPC removing values to a IntValue not working?

Asked by 5 years ago
Edited 5 years ago

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?

0
why would you have local script in gate? karlo_tr10 1233 — 5y
0
@karlo_tr10 Because I couldn't do the "FireServer". Fixer1987 95 — 5y
0
I think you should put your gate script into normal script(server script) Yuuwa0519 197 — 5y

3 answers

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago

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)
0
Still not working. :/ Fixer1987 95 — 5y
0
If this is not working then you are doing something wrong or script is disabled karlo_tr10 1233 — 5y
Log in to vote
0
Answered by
Yuuwa0519 197
5 years ago

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)

Answer this question