So I scripted a code that is when you equip a tool, then click E, the ParticleEmitter inside the tool will be attatched to the player’s leg or arm, kinda like super power.
But I did 2 version of scripts and none of them worked. Checked many times and has no idea how to do it.
Any help is appreciated.
Hey there, can you please put the code you’ve written here, I will try to help you through this, also were there any errors in the output?
1 Like
Quite a simple system! Displays the particles on the server + it’s mobile friendly and r6/r15 friendly. You can change the length of the cooldown in the server script and the actual look of the particle.
-- Local Script: Under the tool
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local tool = script.Parent
local onPowerEnabled = ReplicatedStorage:WaitForChild("OnPowerEnabled")
local function activatePower(actionName, inputState, inputObject)
if (inputState == Enum.UserInputState.Begin) then
onPowerEnabled:FireServer()
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction("PowerActivate", activatePower, true, Enum.KeyCode.E)
ContextActionService:SetTitle("PowerActivate", "Activate Power!")
ContextActionService:SetPosition("PowerActivate", UDim2.fromScale(0.95, 0,65))
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction("PowerActivate")
end)
-- Server Script: ServerScriptService
local POWER_COOLDOWN_LENGTH = 10
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local onPowerEnabled = ReplicatedStorage:WaitForChild("OnPowerEnabled")
local powerCooldown = {}
local function handlePowerActivation(player)
if (powerCooldown[player] == nil) then
powerCooldown[player] = player
local character = player.Character
local particle = Instance.new("ParticleEmitter")
-- customise particle to your likings
particle.Parent = character:FindFirstChild("RightUpperArm") or character:FindFirstChild("Right Arm")
Debris:AddItem(particle, 5)
task.wait(POWER_COOLDOWN_LENGTH)
powerCooldown[player] = nil
end
end
onPowerEnabled.OnServerEvent:Connect(handlePowerActivation)
2 Likes
Thanks a lot!
It didn’t work, I will try to find if it’s my problem or maybe a typo in the script.
Most likely, I just wrote this up really quick. The concept is the same however