Trying to make a script where when you touch you get kicked. Help!

Trying to make a script where when you touch you get kicked.

Script inside of part.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = hit.Parent:GetPlayerFromCharacter(hit.Parent)
		game.ReplicatedStorage.Kick:FireClient(plr)
	end
end)

Local Script

game.ReplicatedStorage.Kick.OnClientEvent:Connect(function()
	local plr = game.Players.LocalPlayer
	plr:Kick("You won! You have become an epic gamer!")
end)

Output: “GetPlayerFromCharacter is not a valid member of Model”
What is me doing wrong?

You don’t need to do anything on the client for this.

script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (plr ~= nil) then
		plr:Kick("You won! You have become an epic gamer!")
	end
end)
7 Likes

Thanks! You are one Epic Gamer!

The script must be a Script, not a LocalScript.

Then the code is as follows:

script.Parent.Touched:Connect(function(hitPart)
    local Player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
    if Player then
        Player:Kick('Enter reason here!')
    end
end)
9 Likes