Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

When I try kicking the LocalPlayer, it returns nil?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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
0
You forgot end) 1ov3y0u 51 — 4y
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. XxTrueDemonxX 362 — 4y
0
im cool with you not putting the entire thing bc i would have knew to put end) but thx anyways sean_thecoolman 189 — 4y
Ad
Log in to vote
0
Answered by
1ov3y0u 51
4 years ago
Edited 4 years ago

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)

Answer this question