Remote event refuses to enable my code?

So I have a piece of code I really want to activate via remote event, but it just refuses to work for some reason.

Code where event gets fired to server:

local plr = game:GetService("Players").LocalPlayer
local Tool = script.Parent
local Anim = Tool:WaitForChild("panCombo")
local Mouse = plr:GetMouse()
local Char = plr.Character or plr.CharacterAdded:Wait()
local values = {}
local pan = script.Parent:WaitForChild("Pan")
local hurt = Tool:WaitForChild("DamagePart").HurtScript
local panEvent = game.ReplicatedStorage:WaitForChild("PanAttackEvent")
local panEvent2 = game.ReplicatedStorage:WaitForChild("PanAttackEvent2")

Tool.Activated:Connect(function()
	local animator = Char.Humanoid:FindFirstChildOfClass("Animator")
	if animator then
		local comboPan = animator:LoadAnimation(Anim)
		comboPan:Play()
		if comboPan.IsPlaying == true then
			print(comboPan)
			print(comboPan.IsPlaying)
			panEvent:FireServer(hurt)
		end
	
		comboPan.KeyframeReached:Connect(function(combo1)
			if not values.Button1 then
				panEvent2:FireServer(hurt)
				comboPan:Stop()
			else
				
			end
		end)
		comboPan.KeyframeReached:Connect(function(combo2)
			if not values.Button1 then
				panEvent2:FireServer(hurt)
				comboPan:Stop()
			else
	
			end
		end)
		comboPan.KeyframeReached:Connect(function(combo3)
			if not values.Button1 then
				panEvent2:FireServer(hurt)
				comboPan:Stop()
			else
			
			end
		end)
	end
end)


Mouse.Button1Down:Connect(function(input, gameProcessed) 
	if gameProcessed then return end

	values.Button1 = true
end)

Mouse.Button1Up:Connect(function(input, gameProcessed) 
	if gameProcessed then return end

	values.Button1 = false
end)

Code where event gets received!!!

local panAttack = game.ReplicatedStorage:WaitForChild("PanAttackEvent")

panAttack.OnServerEvent:Connect(function(player, hurt)
	hurt.Disabled = false
	hurt.Name = "ball"
	print(hurt)
end)

the hurt variable is a script that just deals damage, I don’t think it’s necessary to this but I’ll send it anyway:

local hit1 = script.Parent.Parent:WaitForChild("Pan").hit1

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(2)
		hit1:Play()
	end
end)

panEvent2 does the exact opposite of what panEvent does, just disables the script.

This worked fine without remote events (but was kind of broken), but now it just refuses to work.

Do note that the server-side script does work (changes code name, and prints) but it doesn’t enable the script itself for whatever reason.

3 Likes

The script you’re trying to enable doesn’t seem to be a cloned script so I don’t think it’s necessary to send it as an argument of the RemoteEvent to the server. You can just directly access it from the server script.

Try adding this line into the server script:

and removed “hurt” as the second argument in the server script aswell:

Make sure the path to the “hurt” script is correct tho.

1 Like

if this doesn’t fix it, could you share the placement of the scripts please. Also is the hurtscript a local or server script?

1 Like

Sorry I was getting sleep.

I don’t see how putting the hurt variable in the server script would change anything, not to mention Tool is now considered an unknown global because of this:

local Tool = script.Parent

tried referring to it as

local Tool = player.Backpack.Pan...

this didn’t work either, unless I’m doing something wrong entirely.

Server script, here’s the placements of everything:
image

image

1 Like

I replicated your scripts and tried it out. It worked perfectly for me so I don’t really understand.

Maybe you’re script is instantly getting disabled right after it gets enabled. What i mean is maybe the panEvent2 RemoteEvent (the one that disbales the script) fires too early making it seem like the script never got enabled.

Try printing “Firing panEvent2” right after your fire it:

comboPan.KeyframeReached:Connect(function(combo1) -- do this for combo1, combo2, combo3
	if not values.Button1 then
		print("Firing panEvent2")
		panEvent2:FireServer(hurt)
		comboPan:Stop()
	else			
	end
end)

it prints before firing, and after firing too, but only if LMB isn’t held down at that specific keyframe

which is weird to me, if it doesn’t print if LMB is held down, why does the remote event fire??

1 Like

maybe add a debounce

local db  = false

tool.Activated:Connect(function()
	if db == false then
		db = true
		
		--code here
		
		wait(5) --afrer how many seconds can it be used again
		db = false
	end
end)

Also, if i’m not mistaken, KeyframeReached is depricated and you should use GetMarkerReachedSignal instead.

1 Like

debounce does seem to do the trick, however event2 doesn’t seem to fire at all

also

I’ve used KeyframeReached before, it worked fine so I don’t think GetMarkerReachedSignal would change anything, besides the fact I would have to do some sort of animation shenanigans

1 Like

Does it print “Firing panEvent2” in the output? Or is the panEvent2 remoteEvent just not firing?

1 Like

it does print yeah, but the event itself refuses to fire for some reason

1 Like

So the script gets enabled but it refuses to get disabled now?

1 Like

yup, atleast it looks like it, not sure why it doesn’t wanna cooperate

1 Like

Could you show me the script where the “hurt” script gets disabled? Really weird behaviour honestly

2 Likes

oh my god, the disable script was using the same remote event as the enabling one, i changed it up and it works perfectly jiokpfhgsjiopfghsjopiksdfghjiopsfhgpiojk

was this:

local panAttack = game.ReplicatedStorage:WaitForChild("PanAttackEvent")

panAttack.OnServerEvent:Connect(function(player, hurt)
	hurt.Disabled = true
end)

supposed to be this:

local panAttack = game.ReplicatedStorage:WaitForChild("PanAttackEvent2")

panAttack.OnServerEvent:Connect(function(player, hurt)
	hurt.Disabled = true
end)
1 Like

Good to hear you fixed the second issue by yourself. We all make typing faults lol. I’d appreciate the solution mark if you’re cool with it tho, as i helped with the first problem. Glad I could help anyway!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.