Script works in studio but not in game

So, my admin script works nicely in studio but not in game. Here is my code:

--local script
--the player holder value's value is the player itself
Commands.BAN = function()
	game.ReplicatedStorage.PermBan:FireServer(playerHolder.Value.Value, Reason.Text)
end
--script in Server script service

game.ReplicatedStorage.PermBan.OnServerEvent:Connect(function(moderator, target, reason)
	target.Value.Value = true
	
	local Datastores = game:GetService("DataStoreService")
	local banData = Datastores:GetDataStore("BanData")
	
	local success, errorMessage = pcall(function()
		return banData:SetAsync(target, target.Value.Value)
	end)
	
	if success then
		print(target.Name.. " Was succesfully added into the ban datastore")
	else
		print(target.Name.." experienced an error while being added into the ban datasoter")
	end
	
	task.wait(0.1)
	
	target:Kick("You have been permanentaly banned from the game. If you want to appeal, join server xyz. Bannig Moderator: "..moderator.Name)
	
	game.Players.PlayerAdded:Connect(function(plr)
		if plr.Value.Value == true  then
			plr:Kick("You were kicked looool")
			
		end
	end)
end)

Im pretty bad at roblox datastores because I generally use an external site so yeah thanks in advance

1 Like

Any errors in console when playing in game?

Any exploiter can abuse this and ban any players you want.

You need to make a sanity check on the server and make sure only an Admin is requesting it.

1 Like

Nope, not a single one

CHARRAAR

I’ve done that, I didnt add it in my code. It just uses group service to check if a certain member of group xyz is requesting the ban command

Can someone help me bruhs i havent run into this error before so im completely blank on this one

what is this “playerHolder.Value.Value.Value.Value”?

1 Like

Its the player, I’ve already specified it

andoiwndiwanifoiafiaon

Where exactly?


You need to post the code you are using.


This is the information I need to know

  • What does “playerHolder” == ?
  • What does “target” == ?

Really I just need to know what target equals but I’m curious what playerHolder is lol

My whole setup is basically there is an objectValue named (playerHolder) in the Ban text button, whose value is the player, so I can ban or kick the player w/ the GUI

target is just the player on the server script, because im passing the player from the client in FireServer

Okay I think understand.

Tell me if I get this right

  • target == player Instance
  • target.Value == folder
  • target.Value.Value == BoolValue

If this is the information there are two problems

bruh no, lets just leave the whole MAGICAL setup ive made and get into the main issue, However the script is made, it works in studio w/ 0 errors but does not work in game, so can I get some help on that?

Yes if you allow me to help you.

No if you think you are so smart and don’t understand that the setup of your code is a vital aspect of whether it will work or not.

Alright, I will try to explain the whole setup of the code.

--inf is the table in which all of the GUI's are saved.
for _, v in pairs(inf) do

	if v:IsA("TextLabel") and v.Name == "DisplayName" then
		v.Text = player.DisplayName
	end
	
	if v:IsA("TextLabel") and v.Name == "PlayerName" then
		v.Text = player.Name
	end
	

	if v:IsA("TextButton") then
		local playerHolder = Instance.new("ObjectValue")
		playerHolder.Parent = v
		playerHolder.Value = player
		
		v.MouseButton1Click:Connect(function()
			Title.Text = v.Text
			Confrim.Text = v.Text
			Confrim.Value.Value = v
			
		end)
	end
end

Here is a pic of the explorer for more info:

https://gyazo.com/d1c5c85f8a3c840ae0eaf99a95295ee4

Thank you but I don’t need this information all I need to know is what I posted in my post


I will tell you the problems

Going by this statement alone there is already a vital error

SetAsync takes (key,value) if you pass an Instance as a key it will save as Instance[1234] the next time the player joins their Instance will be Instance[98776]

The key should always have the players UserId in it

There are more problems too

  • It’s not shown in your posted code where you set player.Value.Value = true
  • Even if you have another script that will do that your onPlayerAdded code will run before it
1 Like

I think I just realized what you are trying to do

You are trying to save an Instance thinking that the Instance will persist when the player leaves.

Hence this code

1 Like

Oh alright, got it. Im pretty bad w/ datastores so thats why I didn’t know that, thanks

Okay no problem. I’ll explain further.

Instances don’t persist

Firstly you can’t save a player Instance to a datastore, even if you could when a player joins it will create a new Instance

What you need to do is use the players id as key and data as value, then when the player joins you can retrieve that data by doing DataStore:GetAsync(player.UserId) with that data you can do whatever you want like kick the player or construct more Instances and parent them to the player if you want.

I hope I made it clear this time.

1 Like