Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The variable I brought from a remote event is detected as instance, can u help?

So I am trying to make some gui, when I input a players name, then I press the button. I will give a tool to that player in the textbox. So, I am using a remote event and I am transferring variables, when trying to do something it detects it as instance, but it is supposed to be string. When I print the variables, it prints the value correctly.

Local script (In the Gui)

local debounce = false

local food = script.Parent.Parent.Frame.TextLabel.Text

script.Parent.TextButton.MouseButton1Click:Connect(function(clicked)
	if debounce == false and script.Parent.Parent.Parent.Parent.Selected.Text == "N/A" then
		script.Parent.Parent.Parent.Parent.ERROR.Visible = true
		wait(1.5)
		script.Parent.Parent.Parent.Parent.ERROR.Visible = false
		
	elseif debounce == false then
		
		debounce = true
		
		local food = script.Parent.Parent.Frame.TextLabel.Text
		
		local targetuser = script.Parent.Parent.Parent.Parent.Selected.Text
		
		local staff = game:GetService("Players").LocalPlayer.Name
			
		game:GetService("ReplicatedStorage").ServingSystem:FireServer(food, targetuser, staff)
		
		script.Parent.Parent.Parent.Parent.SUCCESS.Visible = true
				
		wait(1)
		
		debounce = false
		
		wait(0.5)
		
		script.Parent.Parent.Parent.Parent.SUCCESS.Visible = false
	end
end)

Normal script (SSS)

game:GetService("ReplicatedStorage").ServingSystem.OnServerEvent:Connect(function(...)
	
	local args = {...}
	
	local selectedplayer = args[1]
	local selectedfood = args[2]
	local staffname = args[3]
		
	print(selectedplayer)
	print(selectedfood)
	print(staffname)
	
	local targetbackpack = game.Players[selectedplayer].Backpack
	
	local newfood = game.ReplicatedStorage.FoodStorage[selectedfood]:Clone()	
	newfood.Parent = targetbackpack
		
	print(staffname.." gave "..selectedplayer.." "..selectedfood)
	
end)

3 comments

0

Kinda messed up the code.

0

The LUA thing ^

0

can u specify where the error is

1 answer

there are. many things wrong with this

first of all, your arguments aren't even in the correct order—it should be targetuser, food, staff on the client

second of all, the first parameter of a RemoteEvent connection will always be the player who fired the event—if you send arg1 and arg2 on the client, the server will get player, arg1, and arg2

third, since RemoteEvents always send the player, there's no reason to send the staff that fired the event

fourth, what's the point of using a variadic function if you're only going to use the first three arguments—you can just do game:GetService("ReplicatedStorage").ServingSystem.OnServerEvent:Connect(function(player, selectedplayer, selectedfood) on the server

game:GetService("ReplicatedStorage").ServingSystem.OnServerEvent:Connect(function(player, target, food)

    print(target)
    print(food)
    print(player)

    local targetbackpack = game.Players[target].Backpack

    local newfood = game.ReplicatedStorage.FoodStorage[food]:Clone()    
    newfood.Parent = targetbackpack

    print(player.Name.." gave "..target.." "..food)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.