That works without the click detector, but if you insist on using a click detector, follow the other replies
- Don’t use game.StarterGui, use player.PlayerGui
- You’re using localPlayer when you’re using a serverScript. That is not how it works…
What you SHOULD do is that from a local script you just connect this function onto your mouse and then fire a remote event to the server to kick the player.
---Client
local remoteEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
function click()
local brick = workspace.Baseplate
local distance = (brick.Position - root.Position).Magnitude
local range = 25
if range > 25 then
if mouse.Target == brick then
remoteEvent:FireServer()
end
end
end
mouse.Button1Down:Connect(click)
-------Server
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player)
player:Kick()
end)
You would have to get the player from the function, not the LocalPlayer.
You should also be using a normal script, not a localscript.
Example:
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
plr.PlayerGui.BlackScreen.Enabled = true
plr:Kick()
end)
Does this work for you?
-- Must be a regular script inside a clickdetector!
script.Parent.MouseButton1Click:Connect(function(plr)
plr:Kick()
end)
EDIT: Replace MouseButton1Click
with MouseClick
!!!
Regular scripts don’t know which player is the LocalPlayer, and LocalScripts don’t run at all when they are inside a brick.
If you put your LocalScript inside of your ScreenGui, and then reference the ClickDetector from outside, it will work.
local LocalPlayer = game.Players.LocalPlayer
local ClickDetector = workspace.Shutdown.ClickDetector
local BlackScreen = script.Parent.BlackScreen
ClickDetector.MouseClick:Connect(function()
BlackScreen.Visible = true
LocalPlayer:Kick()
end)
something like this:
it should be a server script
but first of all place a click detector in the brick (if you don’t have one already)
script.Parent.ClickDetector.MouseClick:Connect(function(plr) -- Detects clicks and find the player who clicked it
local PlayerGui = plr.PlayerGui -- player has it's own "StarterGui" inside him it's called PlayerGui
PlayerGui.BlackScreen.Enabled = true
plr:Kick("text that will appear when they will be kicked") -- Kicks player who clicked it
end)
hope this helped you
try this
local clickdetector = script.parent
local plr = game.Players.LocalPlayer
clickdetector.MouseClick:Connect(function(plr)
plr:Kick()
end)
After, add a script inside the screen(textlabel, textbutton, etc…)
This is the script:
local click = game.workspace.--replace this with the object
click.MouseClick:Connect(function()
game.StarterGui.BlackScreen.Enabled = true
end)
Hello, thanks for posting!
Try this and see if it works, place this in the brick using a normal script. (This is all the code you need)
script.Parent.ClickDetector.MouseClick:Connect(function(plr) -- fires when its clicked. the "plr" is the player who clicked it
plr.PlayerGui.BlackScreen.Enabled = true -- startergui is tranfered into something called "playergui" when the game is started so you need to edit the players gui.
plr:Kick() -- kicks the player, if you want it to display a message do plr:Kick("Put message here")
end)