-
What do you want to achieve? Keep it simple and clear!
I am attempting to add a system where the player goes upon a predefined path after they press a key and touch a requisite object. -
What is the issue? Include screenshots / videos if possible!
After I added a debounce feature to the script, so the remote event could not be reactivated mid-path, the remote event strangely could be triggered after the path was completed by pressing the E key, and it would re-activate the pathing, forcing the player to go upon it again, despite the player not even being in contact with the model.
Here’s is the code below, I don’t want to show the entire PathDirector script because I don’t think its too necessary, but I can provide it if needed!
PathDirector (ModuleScript)
for i = 1, #path do
if i == math.floor(#path * 0.85) then
loadedAnimation:Stop()
anim.AnimationId = animLandingID
loadedAnimation:AdjustSpeed(loadedAnimation.Length / (totalTime/#path))
loadedAnimation:Play()
end
local point = path[i]
local tweenInfo = TweenInfo.new(totalTime / #path, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local properties = {CFrame = CFrame.lookAt(root.Position, point), Position = point}
local tween = TS:Create(root, tweenInfo, properties)
tween:Play()
repeat
wait()
until (root.Position - point).magnitude <= 3 --EXTREMELY close
end
UserInput (LocalScript in StarterCharacterScripts)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local inputEvent = ReplicatedStorage:WaitForChild("Input")
function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.E then
inputEvent:FireServer()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Path (ServerScript, this is a child to the object that is being touched by the player to activate it)
local path = require(game.ServerStorage.PathDirector)
local inputEvent = game:GetService("ReplicatedStorage").Input
local debounces = {}
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
inputEvent.OnServerEvent:connect(function(client)
if player and not debounces[player.UserId] then
debounces[player.UserId] = true
path.start(script.Parent, hit)
debounces[player.UserId] = false
end
end)
end)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried retooling the debounce to remove the player from the table, changing the conditional, using the client object rather than hit, and changing the hit tonil
(which did work to an extent but the touch event would not reactivate). I have tried looking for solutions to this but none have been too useful yet.
Thank you for any help you can provide!