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)
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.
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.
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:
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)
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.
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
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)
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!