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?
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
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)