Hi everyone I’m currently working on a Tool Ability System and I’m a noob Scripter.And rn I want that if the Tool is activated everyone in the playing Team except the one that used the Tool should get Slowed down for 5 seconds and it should have a CooLDown of 10 seconds.I hope this Ability is not hard to do.(Anything helps)
You need to understand Remote events for this, so i’ll explain them in a very easy way, so you should watch a tut about it:
So we have two types of wiews ,
The server , which includes every player so if anything is being made on the server, every player will “see” or use whatever you make.
The Client, which is only the single player, in fact every local scripts works just for the player , and not for every player, so for example, if i change a part’s color trough a localscript i would be the only one to see the changes.
hope this is clear.
so Remote Events are used to communicate between these twos.
First i put the remote event and tool into ReplicatedStorage.
here, this is the local script to detect if the player activates the tool, in StarterPlayerScripts:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Our remote Event
local MyTool = game.ReplicatedStorage.Tool --The tool
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()-- The part after or is so even if the player resets the code doesn’t break
local Humanoid = Character:FindFirstChild(“Humanoid”)
local Players = game.Playerslocal ToolClone = MyTool:Clone()-- Here i clone the tool so a copy of it is always in replicated storage (it’s optional)
Players.PlayerAdded:Connect(function(Player) --this is optional too, i did PlayerAdded because i don’t need to use it, but you can just adjust it to your needs.
Player.Team = game.Teams.Playing
end)local Cooldown = false – The cooldown variable
ToolClone.Parent = LocalPlayer.Backpack – Setting the clone of our tool in the player’s backpack
ToolClone.Activated:Connect(function(Player) – function to detect if the tool’s activated
if Cooldown == true then
return
elseif Cooldown == false then
Cooldown = true
RemoteEvent:FireServer(Player) – Here the SERVER is fired and i pass trough a parameter the player that activated the tool, so i can use it on the serverscript.
wait(10) – Cooldown Time
Cooldown = false
end
end)
and this is the script to do the actual work:
local MyTool = game.ReplicatedStorage.Tool --Get the tool
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local PlayersService = game:GetService(“Players”) – (or game.players)RemoteEvent.OnServerEvent:Connect(function(Player) – The event signal is “captured” by the function
for _,Players in pairs(Player.Team:GetPlayers()) do – Here you loop trough the team of the player that activated the tool, so we can get other player’s on the team.
if Players ~= Player then – If any of the players equals to the activated player, it will return
local PlayersCharacter = Players.Character or Players.CharacterAdded:Wait() --Same thing as before
local PlayersHumanoid = PlayersCharacter:FindFirstChild(“Humanoid”)
PlayersHumanoid.WalkSpeed = 5 – Set the speed you want to slow down
task.wait(5) – Duration
PlayersHumanoid.WalkSpeed = 16 – Sets the speed to normal, 16 default.
else
return
end
end
end)
i hope this helped not only with your current problem but to also understand remote events.
have a good day
(also if your problem is solved click the “Solution” checkmark please)
Ima try it out tomorrow if it doesn’T work ima still click on the Solution button cuz this is a lot of work
no no if it doesn’t work or you got any other questions tell me, it’s not that much of code so don’t worry let me know!
I understand the remote event but I don’t really understand how I can let the tool appear in the starter pack to test it out or in a folder which is in the Replicated Storage.
This is where I want the Tool to be
This is where I have put the Tool I have put it instantly in the Replicated Storage
I also did put the Remote Event instantly in the Replicated Storage
I also want the Tool to be in the Starter Pack so I can test it out
I didn’t rlly explain this well I still hope u understand
You could either copy the tool into the starterpack or you could create a script that gives every player that tool when they join
the script (in serverscriptservice) would look like this:
game.Players.PlayerAdded:Connect(function(player)
local tool = yourpathtothetool:Clone()
tool.Parent = player.Backpack
end)
yeah @Nico_Nic77 that’s how it’s done @NOVITUS12 ,
btw i explained it on the first script:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent --Our remote Event
local MyTool = game.ReplicatedStorage.Tool --The tool
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()-- The part after or is so even if the player resets the code doesn’t break
local Humanoid = Character:FindFirstChild(“Humanoid”)
local Players = game.Players
local ToolClone = MyTool:Clone()-- Here i clone the tool so a copy of it is always in replicated storage (it’s optional)
--------------------- herePlayers.PlayerAdded:Connect(function(Player) --this is optional too, i did PlayerAdded because i don’t need to use it, but you can just adjust it to your needs.
Player.Team = game.Teams.Playing
end)local Cooldown = false – The cooldown variable
ToolClone.Parent = LocalPlayer.Backpack – Setting the clone of our tool in the player’s backpack ----- here
ToolClone.Activated:Connect(function(Player) – function to detect if the tool’s activated
if Cooldown == true then
return
elseif Cooldown == false then
Cooldown = true
RemoteEvent:FireServer(Player) – Here the SERVER is fired and i pass trough a parameter the player that activated the tool, so i can use it on the serverscript.
wait(10) – Cooldown Time
Cooldown = false
end
end)
if you want the tool to be in a folder that is already been created you can just put it there and clone it. and then as shown put it in the player’s backpack. Also if you want the tool to be given when a player join use PlayerAdded event as @Nico_Nic77 said. (sorry for the double pings)
but don’t worry, eventually with practice everything will be more clear and code to read.
if you go any other questions let me know!
Oh sorry, I did not see you had it in the original code. My apologies!
Dont worry as long as it helps him to understand is usefull!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.