Kick player when tool touched part

i cant get this script to work!
the code is

local a = game.Players.LocalPlayer

local b = game.Workspace.fuel

script.Parent.Touched:Connect(function(hit)

if hit.Parent.Name == “fuel” then

a:kick(“you escaped!”)

end

end)

1 Like

Local Player Doesn’t exist in server-side scripts, try this:

script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.Players:GetPlayerFromCharacter(hit.Parent):kick("You Escaped!")
end
end)
1 Like

im trying to make it when a tool touches the part the player gets kicked.

1 Like
-- Local script, inside the tool
local kickEvent = game.ReplicatedStorage:WaitForChild('RemoteEvent') -- Location & name of event

script.Parent.Touched:Connect(function(hit)
    if hit.Name == 'fuel' then
        kickEvent:FireServer()
    end
end)

-- Server script, perhaps in ServerScriptService
local kickEvent = game.ReplicatedStorage:WaitForChild('RemoteEvent')

kickEvent.OnServerEvent:Connect(function(player)
    player:Kick('You escaped!')
end)
1 Like

Assuming the player holding the tool is the one getting kicked, this can be done with a LocalScript.

local plr = game.Players.LocalPlayer
local handle = script.Parent

handle.Touched:Connect(function(hit)
    if hit.Name == "fuel" then
        plr:Kick("You escaped!")
    end
end)

Put this in a LocalScript inside the tool’s handle.

Im sorry! Completely overlooked the word tool… Someone else here I believe has your solution.