So I made an ability that spawns a ball above the player’s head and kind of follows him that can be activated and deactivated
But when 2 or more players try to use it, if one is already spawned for a player and the other player presses click to try to spawn one for him then it spawns a ball on the other player’s location and if he presses click again then it despawns the other player’s working ball . How do I make it so both of them can have it and them using it doesn’t affect the other player.
this is the server script because on the local script it just detects if the player pressed click then fires it
-- Variables
local Remote = game:GetService("ReplicatedStorage"):FindFirstChild("Mori") -- this is for left click
local Remote2 = game:GetService("ReplicatedStorage"):FindFirstChild("MoriFire") -- this is for right click
local mori = game:GetService("ServerStorage"):WaitForChild("mori")
local cooldown = {}
mori.PrimaryPart = mori.Part
local Active = false
local RunService = game:GetService("RunService")
Remote.OnServerEvent:Connect(function(player) -- left click
if Active == false then
if cooldown[player.UserId] ~= "onCooldown" then
local character = player.Character
local humanoidroot = player.Character.HumanoidRootPart
newMori = mori:Clone()
connection2 = RunService.Heartbeat:Connect(function()
if player.Character.Humanoid.RootPart ~= nil then
newMori:SetPrimaryPartCFrame(CFrame.new(character.HumanoidRootPart.Position + Vector3.new(0,5,0)))
else
newMori:Destroy()
connection2:Disconnect()
end
end)
newMori.Parent = workspace
print("click")
Active = true
end
elseif Active == true then
print("active is now false ")
newMori:Destroy()
connection2:Disconnect()
Active = false
cooldown[player.UserId] = 'onCooldown'
wait(10)
cooldown[player.UserId] = nil
end
Remote2.OnServerEvent:Connect(function (player) -- right click
if Active == true then
print("right clicked when active is true")
end
end)