so i made this game where you have to get everything on a shopping list, then you completed the game, but when you collect all the items, im not sure how to kick the player out, i used the gui as the thing that kicks you out, heres the script: "
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local objective1 = script.Parent.Objective1 local objective2 = script.Parent.Objective2 local objective3 = script.Parent.Objective3 local objective4 = script.Parent.Objective4
if objective1.Text == "------" and objective2.Text == "------" and objective3.Text == "------" and objective4.Text == "------"then
player:Kick("congrats, you got all the items on your shopping list!")
end
" it wont work. help?
You have to fire a serverscript to kick the player, you cannot kick the player from a localscript
Basically, you can create a RemoteEvent
by clicking on whatever you want to be the parent and clicking the plus and inserting one, or just add this script into ServerScriptService
local event = Instance.new("RemoteEvent") event.Name = "KickEvent" event.Parent = game.ReplicatedStorage local kickmessage = "congrats, you got all the items on your shopping list!" local function kick(plr) print("The function has been called on " ..plr.Name.. ". Kicking them!" plr:Kick(kickmessage) end event.OnServerEvent:Connect(kick)
and replace your kick within the localscript with this
local event = game.ReplicatedStorage:WaitForChild("KickEvent") event:FireServer()