What am I trying to achieve?
I’m making a PVP system where the player needs to say a specific word and then click on an opposing player or hostile NPC within a limited time to result in damage. I have managed to script the chatted function (which fires animation and effect event) and click on the damage event separately.
My problem now is I don’t know how to combine the two scripts together, along with a limited time frame for the players to click on an opponent.
Script for firing animation and effects:
local RS = game:GetService("ReplicatedStorage") local Animation = game.ReplicatedStorage.Animation.Ani local Toggle = game.ReplicatedStorage.EffectToggle local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() Player.Chatted:Connect(function(message) if message == "Fire" then local Humanoid = Character:WaitForChild("Humanoid") local Ani = Humanoid:LoadAnimation(Animation) Ani:Play() --Fires animation Toggle:FireServer() -- Fires particle event end end)
Script for damage on click:
local Player = game.Players.LocalPlayer local mouse = Player:GetMouse() local RS = game:GetService("ReplicatedStorage") local clickEvent = RS:WaitForChild("Dmg") mouse.Button1Down:Connect(function() local model = mouse.Target:FindFirstAncestorOfClass("Model") if model then local clickedPlayer = game.Players:GetPlayerFromCharacter(model) if clickedPlayer then clickEvent:FireServer(clickedPlayer) -- does damage end end end)
The combined process should be: Say “Fire” in chat → if, click on another player within a limited time (say 5 seconds) → then, fires animation, effects and damage → else, (if 5 seconds are up without clicking someone) End
I’ve tried using wait to create that timespan for players to click on an opponent but nothing has worked. It is possible I’m coding in the wrong sequence. I’ve heard of loops and clickdetectors but I’m not sure how, or if I should, include them in the script. Some mentoring and feedback would be appreciated. Thank you.