Splitting RemoteFunctions

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?

2 Likes

Why not detect for a click of the button from the script instead of using remotes? you can then listen for click and releases.

I dont understand, you mean, detect when a player presses a key in that script and make it happen?

1 Like

The button the person presses, can’t you detect when they press it from that script you’re using?

Its not a button, its a key, i dont know about keys, ive tried it before.

1 Like

I don’t know what you mean by keys

I have more than just that script that is apart of the whole thing, but it will be alot to show. What i mean by keys are keys on a keyboard.

1 Like

Then when passing the parameters to the remote you can pass whether it is released or not in that other script