When I send over the table (SelectedOre) with a remote event it send out something different than wants being printed below it. The print is printing the correct thing but the FireServer is not.
If you could show the table being passed, and what is being received it would help figure out the problem.
My current guess is that when bindable or remote events pass tables as arguments they pass a shallow copy of the table, so deeper tables aren’t being passed as expected.
The table is being updated every time a button is pressed. It just deletes everything in there from the last button press and puts in the new data. At least its supposed to. It does delete and replace the data but everything being passed is just the first set of data, never the newest one. If that makes sense.
The mouseclick event has already passed the table selectedore with whatever values it started with to the bindableEvent.
You need to update the reference to the table after is has the new values.
Edit: I’m not sure the code I posted would work actually as I’m not sure how you have defined selectedOre, or which scope it was defined in.
Button.MouseButton1Click:Connect(function()
local Middle = Forgery.CustomBlade.Middle
local Edge = Forgery.CustomBlade.Edge
SelectedOre = Ore.Name
Middle.BrickColor = Ore:FindFirstChild("Part").BrickColor
end)
BTW I changed it from a table to just ONE variable, and it still does not work, even though no matter where I put a print statement it will say its right, but never actually send the right variable.
Make sure your table isn’t a mix of an array and a dictionary, as when it will be serialized (I think it’s just transformed into a json table) it can either be a dictionary or an array, but not both
If that isn’t the case, make sure you are reading the correct argument, as @MilkyFiend pointed out. The first argument will always be the player who sent the remote, so all of the other arguments are shifted by 1 position
Without the structure of the table you are sending or the server sided code, we can’t be sure of the cause of the issue
Ok, I will make them print twice in the same test to show you my exact problem.
1st:
(Might as well throw in ALMOST my whole script)
local SelectedOre
Event.OnClientEvent:Connect(function()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local Backpack = Player.Backpack:GetChildren()
Forgery.CustomBlade.Edge.BrickColor = BrickColor.new("Medium stone grey")
Forgery.CustomBlade.Middle.BrickColor = BrickColor.new("Dark stone grey")
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
Gui.Anvil.MainFrame.Visible = true
for _, Ore in pairs(Backpack) do
if Ore:IsA("Tool") then
if Ore.Name:match("Ore") then
local Button = Instance.new("TextButton")
local Name = string.split(Ore.Name," ")
Button.Parent = Ores
Button.Name = Ore.Name
Button.Text = Name[1]
Button.TextScaled = true
Button.Font = "GrenzeGotisch"
Button.MouseButton1Click:Connect(function()
local Middle = Forgery.CustomBlade.Middle
local Edge = Forgery.CustomBlade.Edge
SelectedOre = Ore.Name
print(SelectedOre)
Middle.BrickColor = Ore:FindFirstChild("Part").BrickColor
end)
end
end
end
end)
Create.MouseButton1Click:Connect(function()
Gui.Anvil.MainFrame.HandleText.Visible = true
Gui.Anvil.MainFrame.ChooseHandle.Visible = true
print(SelectedOre)
Event2:FireServer(Forgery.CustomBlade, workspace.CurrentCamera, SelectedOre)
print(SelectedOre)
end)
and my whole server script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.AnvilRemotes.SwordCreated
local Event2 = ReplicatedStorage.AnvilRemotes.AnvilClicked
Event.OnServerEvent:Connect(function(Player,Sword,Camera,SelectedOre)
local Character = Player.Character
if Character then
local Backpack = Player.Backpack:GetChildren()
local Gui = Player.PlayerGui
local HandleSelection = Gui.Anvil.MainFrame.ChooseHandle
local Handles = HandleSelection:GetChildren()
local Names = {}
for _, child in pairs(Handles) do
if child:IsA("TextButton") then
table.insert(Names, child.Name)
end
end
for _, Handle in pairs(Backpack) do
if Handle.Name:match("Handle") then
if Handle.Name == table.unpack(Names) then return end
local Button = Instance.new("TextButton")
Button.Name = Handle.Name
Button.Parent = HandleSelection
Button.Text = Handle.Name
Button.TextScaled = true
Button.Font = "GrenzeGotisch"
Button.MouseButton1Click:Connect(function()
local BackpackItems = Player:FindFirstChild("Backpack"):GetDescendants()
print(SelectedOre)
for _, Item in pairs(BackpackItems) do
if Item:IsA("Tool") then
if Item.Name == SelectedOre then
print(SelectedOre)
Item:Destroy()
end
end
end
Handle:Destroy()
Event:FireClient(Player)
end)
end
end
end
end)
In order of appearance:
Local:
It prints the correct ore (the one I am choosing/chose)
It prints the ore I chose.
It prints the ore I chose.
Server:
It prints the ore I chose
It prints the ore I chose
2nd test (same test server):
Local:
It prints the correct one (the one I am choosing/chose)
It prints the ore I chose.
It prints the ore I chose.
Server:
It prints the old ore I chose.
prints nothing.
Keep in mind I also destroy the ore I chose everytime I pressed a certain button.
I am not sure how to explain what the problem here is but I’ll try :
You have MouseButton1Click function and creating the button insdie on the first fire and not updating the values… so bascially even when you click multiple times any button you’ve created in that script it will have the same value and not change… AHH My head is burning… It’s really hard to explain stuffs… But just so you know you are not changing the existing value of the buttons or something…
I can make you a small place and write a code for you to take an example as If youtell me you are tryng to do in these 2 scripts if you don’t understand it…
Edit : I also don’t understand what your script is suppose to do… like you are just creating buttons for ores in each? or the server is for sword bttns? It’s like I know what’s happening but I am just getting this pain in my head everytime I think about it like seems so hard to explain…
1: I think I know what your trying to say but fyi the BrickColor and stuff is changing, so ig just the value is not.
2: Epic
3: lol ik, lots of people say my scripting isnt very “understanding” to most, but I understand it so thats all that matters. It is a make your own sword script, and you can use ores you have in your inventory to change the color of the blade and soon its stats.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event2 = ReplicatedStorage:WaitForChild("YourRemoteEvent")
local SelectedOre = {}
local Create = script.Parent -- Replace with the actual reference to your button
local Gui = game.Players.PlayerGui:Waitforchild("YourGUIName")
Create.MouseButton1Click:Connect(function()
UpdateSelectedOre()
Gui.Anvil.MainFrame.HandleText.Visible = true
Gui.Anvil.MainFrame.ChooseHandle.Visible = true
if SelectedOre then
Event2:FireServer(Forgery.CustomBlade, workspace.CurrentCamera, SelectedOre)
print("Selected Ore:", SelectedOre)
else
warn("SelectedOre is not defined or nil.")
end
end)
It seems like you are experiencing an issue where the data being sent through the RemoteEvent (Event2:FireServer ) is not reflecting the updated table content. This could happen if the table is not being updated correctly, or if the data is not being serialized properly when passed to the server.
Ensure that the SelectedOre variable is defined in the correct scope. If it’s defined outside the button click event, make sure it’s not being overridden or modified elsewhere in your script.
Alright let me try to tell you what I mean again since my brain feels refreshed.
What you are trying to do is to print selectedore from the old buttons you’ve created using the event you’ve fired to the server.
The problem here is that you are clicking the old buttons that you’ve created using that event. If you want the new data or ore you’ll have to click the new button you’ve created using the new fired event / function.
Why is that? Simply because you have your print statement when you click the buttons so basically you are not updating the selected ore for the old buttons you’ve created using the server.
Try putting the print statement just after this line it should always print the right value every time you dire that event.
If you still don’t understand it I can explain it in a better way using real life as an example if you want.
One other thing is that don’t use server to handle (change/create) playergui directly.
Just use remoteevents and change or create gui from the client side. (Less lag).