You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to make it so only the person who pressed the ability keycode will use the ability.
What is the issue? Include screenshots / videos if possible!
The issue is that if one person presses the ability keycode, all players holding the weapon will use the ability.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to find solutions on the Developer Hub but I couldn’t find any.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
These scripts are inside the tool.
This is the local script.
local AnimationEvent = game.ReplicatedStorage.Folder.ClassAbility
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Tool = script.Parent
local Turn = 1
local Cooldown = 10 -- set this to the amount of seconds you want it to wait after an attack
UIS.InputBegan:Connect(function(input)
if Tool.Parent == Player.Backpack then print("Equip it!!!!")
elseif input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.E then
AnimationEvent:FireServer()
Turn = 2
if Turn == 2 then script.Disabled = true wait(Cooldown) script.Disabled = false
else end
end
end
end)
This is the server script.
local AnimationEvent = game.ReplicatedStorage.Folder.ClassAbility
local Animatione = Instance.new("Animation")
Animatione.AnimationId = "rbxassetid://14696844916"
local Damage = 500
local SuperDMG = 1500
AnimationEvent.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local Character = game.Workspace:FindFirstChild(plr.Name)
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(Animatione)
AnimationTrack:Play()
script.Parent.Hitbox.SlamParticles.Enabled = true
script.Parent.Handle.SuperTrail.Enabled = true
wait(0.3)
script.Parent.AbilHitbox.ParticleEmitter.Enabled = true
script.Parent.CanAbilDMG.Value = true
wait(0.5)
script.Parent.CanAbilDMG.Value = false
script.Parent.AbilHitbox.ParticleEmitter.Enabled = false
script.Parent.Hitbox.SlamParticles.Enabled = false
script.Parent.Handle.SuperTrail.Enabled = false
end)
script.Parent.AbilHitbox.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local Humanoid = Hit.Parent.Humanoid
if script.Parent.CanAbilDMG.Value == true then
Humanoid:TakeDamage(Damage)
script.Parent.CanAbilDMG.Value = false
end
end
end)
script.Parent.Hitbox.Touched:Connect(function(SuperHit)
if SuperHit.Parent:FindFirstChild("Humanoid") then
local Humanoid = SuperHit.Parent.Humanoid
if script.Parent.CanAbilDMG.Value == true then
Humanoid:TakeDamage(SuperDMG)
script.Parent.CanAbilDMG.Value = false
if Hit and Hit.Parent:FindFirstChild("Humanoid") then
Humanoid = Hit.Parent.Humanoid
Humanoid.PlatformStand = true -- Stun
wait(3)
Humanoid.PlatformStand = false -- Unstun
end
end
end
end)
I have no clue what the problem is as I am pretty terrible at scripting.
Any help would be very much appreciated!
I can provide extra information if needed.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Try moving the entire OnServerEvent on the server to the local script, every single tool will receive the event as it is connected and will trigger items in script’s parent
Unfortunately, all the solutions here didn’t work, it may be because I didn’t do the solutions correctly but most of the time trying these just made the whole ability not work.
Oops nevermind, it will not show for other players
Try to check if the tool is in the character who activated it
AnimationEvent.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local Character = game.Workspace:FindFirstChild(plr.Name)
if script.Parent.Parent ~= Character then return end
-- if tool isn't in player's character then stop
--rest of code
Provided that script.Parent is the tool and the tool is in the character (script.Parent.Parent) when equipped, this works
I am not completely understanding, but I am pretty sure the tool isn’t in the players character model since the ability doesn’t work when I press E.
I tried it again and the script worked as intended! Thank you so much!
If anyone wants the full script after its fixed, here it is.
local AnimationEvent = game.ReplicatedStorage.Folder.ClassAbility
local Animatione = Instance.new("Animation")
Animatione.AnimationId = "rbxassetid://14696844916"
local Damage = 500
local SuperDMG = 1500
AnimationEvent.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local Character = game.Workspace:FindFirstChild(plr.Name)
if script.Parent.Parent ~= Character then return end
-- if tool isn't in player's character then stop
--rest of code
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(Animatione)
AnimationTrack:Play()
script.Parent.Hitbox.SlamParticles.Enabled = true
script.Parent.Handle.SuperTrail.Enabled = true
wait(0.3)
script.Parent.AbilHitbox.ParticleEmitter.Enabled = true
script.Parent.CanAbilDMG.Value = true
wait(0.5)
script.Parent.CanAbilDMG.Value = false
script.Parent.AbilHitbox.ParticleEmitter.Enabled = false
script.Parent.Hitbox.SlamParticles.Enabled = false
script.Parent.Handle.SuperTrail.Enabled = false
end)
script.Parent.AbilHitbox.Touched:Connect(function(Jit)
if Jit.Parent:FindFirstChild("Humanoid") then
local Humanoid = Jit.Parent.Humanoid
if script.Parent.CanAbilDMG.Value == true then
Humanoid:TakeDamage(Damage)
script.Parent.CanAbilDMG.Value = false
end
end
end)
script.Parent.Hitbox.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local Humanoid = Hit.Parent.Humanoid
if script.Parent.CanAbilDMG.Value == true then
Humanoid:TakeDamage(1500)
script.Parent.CanAbilDMG.Value = false
if Hit and Hit.Parent:FindFirstChild("Humanoid") then
Humanoid = Hit.Parent.Humanoid
Humanoid.PlatformStand = true -- Stun
wait(3)
Humanoid.PlatformStand = false -- Unstun
end
end
end
end)