Hello guys once again, i found another issue but this time it’s a BIG issue…
Script:
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
-- You can ignore these 3 but i recommend to keep it to make it as a shorten way on the lines.
script.Parent.MouseButton1Click:Connect(function()
if username.Text == game.Players then
print("You kicked "..username.Text)
if game.Players:FindFirstChild(username.Text) then
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
end
else
if username.Text ~= game.Players then
warn("You tried to kick "..username.Text.." but it's an invalid username !")
end
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end)
Warning, it’s a LocalScript, it’s in the KickButton and the AdminPanel Gui it’s on the Handler Script which is in the ServerScriptService.
I believe the text saying “Cannot write to DataStore from studio if API access is not enabled.” means that it cannot write to a datastore from studio if api access if not enabled. I could be wrong though.
Also, it’s giving the warning because you’re trying to see if a string is not an instance. Obviously all strings aren’t instances, so it’s going to give you that warning.
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if game.Players:FindFirstChild(username.Text) then
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
print("You kicked "..username.Text)
if username.Text == "" then
warn("You tried to kick an unknow person but it's an invalid username !")
end
end
end)
I keep getting better and better in scripting, man.
Script:
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if username.Text == "" then
warn("You tried to kick an unknow person but it's an invalid username !")
else
warn("You tried to kick "..username.Text.." but it's an invalid username !")
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end
end)
Videos (Still warns me even though the username is correct at the 1st video):
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if game.Players:FindFirstChild(username.Text) then
warn("The username is valid and the player will be kicked shortly")
else
warn("You tried to kick "..username.Text.." but it's an invalid username !")
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end
end)
The problem was in this part:
if username.Text == "" then
warn("You tried to kick an unknow person but it's an invalid username !")
else
warn("You tried to kick "..username.Text.." but it's an invalid username !")
Here, if the username was nothing then it would warn that it was unknown and if it was anything else either it is invalid or a valid username, it would execute the else statement.
If this solved the problem don’t forget to mark the topic as solved.
My script works, not yours, sorry because it has a blank on the line 9.
So i like to prefer to do:
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if username.Text == "" then
warn("You tried to kick an unknow person but it's an invalid username !")
else
warn("You tried to kick "..username.Text.." but it's an invalid username !")
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end
end)
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if not game.Players:FindFirstChild(username.Text) then
warn("You tried to kick "..username.Text.." but it's an invalid username !")
else
warn("The username is valid and the player will be kicked shortly")
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end
end)
My bad there was a small mistake. It should work now
Here’s all you need for the Client side of it (LocalScript)
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if not game.Players:FindFirstChild(username.Text) then
warn("You tried to kick "..username.Text.." but it's an invalid username !")
return
end
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
-- Removed the LocalPlayer kick, what were you even trying to accomplish there?
end
end)
Now, if you would, please send your ServerScript that handles the “KickPlayer” RemoteEvent in ReplicatedStorage, if you don’t have one, I’ll make you one.
I need to know EXACTLY what you want to do.
You’re not giving me anymore info, you’re just outright denying the offer of assistance.
I don’t mean to be rude, but if you’re going to ask for help, you’ll have to put the effort in to give those who care to help info, and more importantly, a chance to help.
Try this version, it should fix the small detail you had concerned.
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if username.Text:gsub("%s", "") == "" then -- :gsub("%s", "") just ensures we do not count " " as a username
warn("You must supply a username before kicking.")
return
end
if not game.Players:FindFirstChild(username.Text) then
warn("There is no Player named \""..username.Text.."\" in the server!")
return
end
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
-- Removed the LocalPlayer kick, what were you even trying to accomplish there?
end
end)
We will get down to the “Kicking” part of the script later, you should never kick on the Client, you need a server script, which as I said, we will get to soon.
local username = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if username.Text:gsub("%s", "") == "" then -- :gsub("%s", "") just ensures we do not count " " as a username
warn("You must supply a username before kicking.")
return
end
if not game.Players:FindFirstChild(username.Text) then
warn("There is no Player named \""..username.Text.."\" in the server!")
return
end
if game.Players:FindFirstChild(username.Text) then
print("You kicked "..username.Text)
game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
game.Players.LocalPlayer:Kick(reason.Text)
if reason.Text == "" then
game.Players.LocalPlayer:Kick("Unknow reason given.")
else
game.Players.LocalPlayer:Kick(reason.Text)
end
end
end)
Thanks to @IDoLua to help me. @elomala, Thanks to try to help me. @cpguy5089, Thanks to try to help me.