The script’s purpose is to heal you with a tool when you press right click, and if a random player touches the MeshPart of the tool they get kicked.
Everything works outside of the kicking, and when it does it makes a new event each time and I do not have a clue on how to make this work.
This is my attempt:
local script on the tool:
local tool = script.Parent
local equipped = false
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
mouse.Button2Down:Connect(function()
if not equipped then return end
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteEvent:FireServer()
end)
Server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local ServerStorage = game:GetService("ServerStorage")
local tool2 = ServerStorage:FindFirstChild("CHOO CHOO") -- the Tools name and its on Server Storage because its gonna be copied to specific players
local Players = game:GetService("Players")
remoteEvent.OnServerEvent:Connect(function(player)
print(player.Name .. " fired")
if player.Character then
print('h')
player.Character.Humanoid.Health += player.Character.Humanoid.MaxHealth/2
local toolkick = player.Character
local toolman = toolkick:WaitForChild("CHOO CHOO") -- don't really know if I need to do WaitForChild to get a specific name
local function kick(otherPerson)
local character = otherPerson.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
Players:FindFirstAncestor(character):Kick()
end
end
toolman.MeshPart.Touched:Connect(kick)
end
end)
-- from here onwards its not the problem this just makes a copy of the tool from the ServerStorage to some people
local userId = 716655375
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if player.UserId == userId or player.UserId == 211915203 or player.UserId == 337640276 then
player.CharacterAdded:Connect(function(character)
tool2:Clone().Parent = character
end)
end
end)