Issue with remote event

I gotta check if the object he sent in the remote event is part of the GemButtons_Folder?

Like a simple if statement?

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	if GemsButtons_Folder:FindFirstChild(textbutton) and textbutton:IsA("TextButton") then
		local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
		if TextButton then
			print("Text Button has been cloned")
			TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
		end
	end
end)

Will this make the script harder to exploit?

I was thinking this

Loot_to_Inventory_Event.OnServerEvent:Connect(function(Player, Button)
	if typeof(Button) == "Instance" and Button:IsDescendantOf(Player:WaitForChild("PlayerGui"):WaitForChild("InventoryFrame")) then
		local NewButton = Button:Clone()
		
		NewButton.Parent = Player:WaitForChild("Inventory")
	end
end)

either way, the issue with your script seems to be that you’re using is that you’re using findfirstchild with an instance, this should work

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	if GemsButtons_Folder:FindFirstChild(textbutton.Name) and textbutton:IsA("TextButton") then
		local TextButton = GemsButtons_Folder:FindFirstChild(textbutton.Name)
		if TextButton then
			print("Text Button has been cloned")
			TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
		end
	end
end)

textbutton is a String, not an instance.

thats how I launch it on the client

textbutton.MouseButton1Down:Connect(function()
			Loot_to_Inventory_Event:FireServer(textbutton.Name)
			--Make a new TextButton so its not clickable
			textbutton:Clone().Parent = PlayerGui:WaitForChild("InventoryScreenGui"):WaitForChild("InventoryFrame").ScrollingFrame
			textbutton:Destroy()
		end)

the script you gave me is for server and on the server script, textbutton is a String, not an Instance like on the client (because I passed the server the name of the textbutton)

2 Likes

OH that makes sense, your use of IsA on the string confused me a lot

would this work for you?

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	
	if TextButton and TextButton:IsA("TextButton") then
		print("Text Button has been cloned")
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end
end)

ERROR
attempt to index nil with 'IsA'
Because the server cant find the damn GemButton_Folder when its clearly there

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	if TextButton:IsA("TextButton") and TextButton then
		print("Text Button has been cloned")
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end
end)

But will this make it harder to exploit tho?

it’s harder to exploit, but try directly copying and pasting it from my post
this checks if the textbutton exists properly before calling IsA on it

if TextButton and TextButton:IsA("TextButton") then

this does not

if TextButton:IsA("TextButton") and TextButton then

I did, this.
I found something that may explain the issue!

When I print every child inside the GemButtons_Folder, the one I need is Missing!

image
In this image, I had Citrine (which is missing)

well that’s confusing, now I’m curious if you’re deleting it in some other script without knowing it
I could be wrong, but I think there’s no reason why the remote would be deleting the object

I FOUND THE ISSUE!!!

Basically, I forgot to add Clone() so when I was moving the TextButton, it was the ORIGINAL TextButton from the ServerStorage, not the one I cloned!

local ClonedGemButton = GemsButtons_Folder:FindFirstChild(gem.Name):Clone()

I forgot the :Clone()

Thank you for your help! :))

awesome, glad to see you got it fixed :slight_smile:

Btw, this script is harder to exploit right? What else should I do?

Loot_to_Inventory_Event.OnServerEvent:Connect(function(plr, textbutton)
	local TextButton = GemsButtons_Folder:FindFirstChild(textbutton)
	if TextButton and TextButton:IsA("TextButton") then
		TextButton:Clone().Parent = plr:FindFirstChild("Inventory")
	end
end)

yeah that’ll work, since it’s just a string currently, it’s perfectly fine

1 Like