Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When I try kicking the LocalPlayer, it returns nil?

Code I have so far:


script.Parent.ClickDetector.MouseClick:Connect(function()
script.Parent.ClickDetector.MaxActivationDistance = 0
local TS = game:GetService("TweenService")
local part = script.Parent
local info = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, true, 0)
local goals = {Position = Vector3.new(17, 5, 43.54),}
local tween = TS:Create(part,info,goals)
	tween:Play()
	wait(5)
----------------------Don't mind the above, its just the button tweening and stuff
	game.Players.LocalPlayer:Kick("get nae naed")
end)

So I'm currently making this really dumb game where there's literally nothing except a baseplate and a button. When you press the button, it's supposed to kick the LocalPlayer out of the server, but it returns nil in the output.

Workspace.button.Script:11: attempt to index field 'LocalPlayer' (a nil value)

When I run the line where it is supposed to kick the player, it works perfectly.

You have been kicked from the game: Get nae naed"

What am I doing wrong?

2 answers

✓ Accepted answer

Local Player can only be used in a local script. But clickdetectors automatically pass whichever player clicked them so all you have to do is use that variable.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)

plr:Kick("get nae naed") --Then for the actual kicking

3 comments

0

You forgot end)

0

No. I didn't provide it because I'm not giving him a script. I'm giving him the two pieces he needs to change.

0

im cool with you not putting the entire thing bc i would have knew to put end) but thx anyways

Your script must be put in a localscript. Instead use the following in a serverscript:

--Add your tweening script here
script.Parent.Clickdetector.MouseClick:Connect(function(plr) --or player idk lol

player:Kick("pp")
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.