Okay so. Say that I have a RemoteFuction. If in a regular script i were to invoke that event when they press a button. But if they stop pressing the button, then it will do the part of the RemoteFunction where is stops.
Heres an example:
local tool = script.Parent.Parent.Parent
local rp = game:GetService("ReplicatedStorage")
local dead = Enum.HumanoidStateType.Dead
local folder = rp.Rotation
function Damage(c, s)
local hrp = c.HumanoidRootPart
local pos = hrp.Position
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("Model") and v:FindFirstChild("Humanoid") and v.Humanoid:GetState() ~= dead and v.PrimaryPart and v ~= c then
if (v.PrimaryPart.Position - pos).Magnitude <= 13 then
v.Humanoid:TakeDamage(tool:GetAttribute("Damage"))
local s = folder.hitsound:Clone()
s.Parent = v.PrimaryPart
s:Play()
game.Debris:AddItem(s, s.TimeLength)
local bv = Instance.new("BodyVelocity", v.PrimaryPart)
bv.MaxForce = Vector3.new(100000,100000,100000)
bv.P = 1000
bv.Velocity = CFrame.new(pos, v.PrimaryPart.Position).lookVector * 10
game.Debris:AddItem(bv, 0.2)
end
end
end
end
function Server(plr, pos)--/WHAT I WANT TO HAPPEN WHEN THEY PRESS THE BUTTON
local c = plr.Character
local hum = c.Humanoid
local hrp = c.HumanoidRootPart
local t = Instance.new("Animation")
t.AnimationId = "rbxassetid://6792102529"
local animator = hum:FindFirstChild("Animator") or Instance.new("Animator", hum)
local a = animator:LoadAnimation(t)
a:Play()
hum.AutoRotate = false
hrp.Anchored = true
local RotationEffect = folder.RotationEffect:Clone()
local obj = Instance.new("ObjectValue", RotationEffect)
obj.Name = "Character"
obj.Value = c
RotationEffect:SetAttribute("Stop", false)
RotationEffect:SetPrimaryPartCFrame(CFrame.new(pos))
RotationEffect.Parent = workspace.FX
RotationEffect:WaitForChild("Sphere")
coroutine.wrap(function()
local t = 12
for i = 1, t do
Damage(c, RotationEffect.Sphere)
wait(tool:GetAttribute("Length")/t)
end
end)()
wait(tool:GetAttribute("Length"))--/WHAT I WANT TO HAPPEN WHEN THEY STOP PRESSING THE BUTTON
RotationEffect:SetAttribute("Stop", true)
hum.AutoRotate = true
hrp.Anchored = false
a:Stop(0.3)
wait(1)
RotationEffect:Destroy()
end
script.Parent.OnServerInvoke = Server
How would that work, or if i wont work, how wont it work?