-
What do you want to achieve?
I have a morph that changes the player into a specific character and clones some ability scripts for them. I have regular scripts with the functions and a localscript used for contextaction. -
What is the issue?
I tested this out using two players and whenever a new player uses the morph, the previous player loses connection to the remote events.
Attack Script example:
local AttackEvent = Instance.new("RemoteEvent")
AttackEvent.Name = "AttackEvent"
AttackEvent.Parent = game.ReplicatedStorage
local Tool = script.Parent:WaitForChild("Weapon")
local Animator = script.Parent.Humanoid.Animator
-----------------------------------------------------------------------
local LeftFist = script.Parent.Weapon.LeftFist
local RightFist = script.Parent.Weapon.RightFist
local User = script.Parent
local Attacking = false
local WeaponSound = Instance.new("Sound")
WeaponSound.SoundId = "rbxassetid://5835032207"
WeaponSound.Volume = .12
local Combo1Animation = script.Parent.Humanoid.Combo1
local Combo2Animation = script.Parent.Humanoid.Combo2
local Combo3Animation = script.Parent.Humanoid.Combo3
local Combo1Track = Animator:LoadAnimation(Combo1Animation)
local Combo2Track = Animator:LoadAnimation(Combo2Animation)
local Combo3Track = Animator:LoadAnimation(Combo3Animation)
local Combo = 1
local LastAttack = 0
_G.Cooldown = .6
------------------------------------------------------------------------------------
local function Attacking()
local Tick = tick()
print("Attack")
if Tick - LastAttack > _G.Cooldown then
if Tool.Activated and Combo == 1 then
Attacking = true
Combo1Track:Play()
WeaponSound.Parent = RightFist
WeaponSound:Play()
Combo = 2
LastAttack = tick()
task.wait(_G.Cooldown)
Attacking = false
else
if Tool.Activated and Combo == 2 then
Attacking = true
Combo2Track:Play()
WeaponSound.Parent = LeftFist
WeaponSound:Play()
Combo = 3
LastAttack = tick()
task.wait(_G.Cooldown)
Attacking = false
else
if Tool.Activated and Combo == 3 then
Attacking = true
Combo3Track:Play()
WeaponSound.Parent = RightFist
WeaponSound:Play()
Combo = 1
LastAttack = tick()
task.wait(_G.Cooldown)
Attacking = false
end
end
end
end
end
RightFist.Touched:connect(function(hit)
local model = hit:FindFirstAncestorOfClass("Model")
if model and model:FindFirstChild("Humanoid") and Attacking then
model:FindFirstChild("Humanoid"):TakeDamage(10)
Attacking = false
end
end)
LeftFist.Touched:connect(function(hit)
local model = hit:FindFirstAncestorOfClass("Model")
if model and model:FindFirstChild("Humanoid") and Attacking == true then
model:FindFirstChild("Humanoid"):TakeDamage(10)
Attacking = false
end
end)
AttackEvent.OnServerEvent:Connect(Attacking)
The script used for morphs destroys the previous instances of remote events, so there’s never more than one.
The localscript:
Tool.Activated:Connect(function(Attacking)
AttackEvent:FireServer(Attacking)
end)
I’m fairly new and amateurish with roblox scripting and I can’t seem to understand the issue, any help would be greatly appreciated, thank you.