local ReplicatedStorage = game:GetService("ReplicatedStorage") local humanoid =…
- User
local ReplicatedStorage = game:GetService("ReplicatedStorage") local humanoid = script.Parent local npcModel = humanoid.Parent local returnPoint = game.Workspace:WaitForChild("powrotmng") local PlayerEvent = ReplicatedStorage:WaitForChild("Player") local eventConnected = false while true do script.Parent.Script.Enabled = false
task.wait() if not returnPoint then warn("Return point not found!") break end humanoid:MoveTo(returnPoint.Position) humanoid.MoveToFinished:Wait() print("przyszedl") PlayerEvent.OnServerEvent:Connect(function(player) print("no ten 1") PlayerEvent:FireClient(player) print("Signal sent to client") end) eventConnected = trueend
it need to send that fireclient 1 time only and the same with prints here
Assistant
Your script has a few issues that need to be addressed to make it work as intended (firing the client event only once and printing messages only once). Here's the corrected version:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local humanoid = script.Parent local npcModel = humanoid.Parent local returnPoint = game.Workspace:WaitForChild("powrotmng") local PlayerEvent = ReplicatedStorage:WaitForChild("Player") local hasFired = false -- Disable the script initially (if this is what you want) script.Parent.Script.Enabled = false if not returnPoint then warn("Return point not found!") return end -- Move the NPC to the return point humanoid:MoveTo(returnPoint.Position) humanoid.MoveToFinished:Wait() print("przyszedl") -- This will print once when NPC arrives -- Set up the event connection (only once) if not hasFired then PlayerEvent.OnServerEvent:Connect(function(player) print("no ten 1") -- This will print once when event is received PlayerEvent:FireClient(player) print("Signal sent to client") -- This will print once after firing hasFired = true end) endKey improvements:
- Removed the infinite
while true doloop which was causing multiple event connections - Added a
hasFiredflag to ensure the event only fires once - Moved the event connection outside the movement logic
- Simplified the flow to make it clearer when things happen
If you specifically want the event to fire exactly once when the NPC arrives at the point (rather than when a player triggers it), you could use this alternative:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local humanoid = script.Parent local npcModel = humanoid.Parent local returnPoint = game.Workspace:WaitForChild("powrotmng") local PlayerEvent = ReplicatedStorage:WaitForChild("Player") local hasFired = false script.Parent.Script.Enabled = false if not returnPoint then warn("Return point not found!") return end humanoid:MoveTo(returnPoint.Position) humanoid.MoveToFinished:Wait() print("przyszedl") if not hasFired then -- Fire for all players (or specify a particular player) for _, player in ipairs(game.Players:GetPlayers()) do PlayerEvent:FireClient(player) end print("Signal sent to client(s)") hasFired = true end- Removed the infinite
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.