How can I send data like a part from client to server?

I’ve got a character creation system, when you click a button that is a “Hair style” in this case. I store the hair model inside the button, and put the hair on in the server script. Atm the hair is just in the workspace. But I want to transfer the Hair to the button to keep everything neat, also I don’t know which button is pressed. Unless you can pass button data to the server?

1 Like

So not a part, a part that has already been created

You’re better off storing your assets somewhere like ReplicatedStorage, and firing a remote with data (such as a string) that corresponds to that particular asset, e.g. assigning an ID to each hair asset and applying it on the server when the user selects it.

2 Likes

Pass the reference of the hair to the server, and then equip it on the server.

1 Like

Oh That makes alot more Sense ! Try something like this (Beginner Example) :

local script:

local Event = game.ReplicatedStorage:WaitForChild("Event")
local Button = ("Refrence ur button")
local CurrentHair = nil

Button.MouseButton1Click:Connect(function()
 CurrentHair = "01"
 Event:FireServer(CurrentHair)
end)

script:

local Event = game.ReplicatedStorage:WaitForChild("Event")
local Character = nil
Event.OnServerEvent:Connect(function(player, Hair)
      Character = player.Character or Player.CharacterAdded:Wait()
           if Hair == "01" then
            --- get the hair from somewhere and put it on the character
           end
end)
4 Likes

Dunno if that is secure in anyway, however it does print. And I am able to click on the output with the given part
image
BUT This won’t work for created instances on the client (i believe?)

localscript:

game.ReplicatedStorage.RemoteEvent:FireServer(workspace.Baseplate)

server-script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, part)
    print(part, part.Name)
end)

Still doesn’t work. Like I said before, you can not send any instance through remote events.

1 Like

you maybe didn’t understand me

local Event = game.ReplicatedStorage:WaitForChild("Event")

local Part = workspace.Part

Event:FireServer(Part)
1 Like

Oh, sorry, yea I didn’t understand.

Would this be safe? What if client alters part and sends the altered part to server?

Are you able to tell me what is wrong here? I’m trying to attach a hat to my characters head in the workspace. This worked when I was using the remotefunction, but now changing to this method it’s no longer working. It creates the hat but it creates the hat on top at the origin and it just falls instead of attaching to the character. Any ideas?

local script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")


local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
local Button = script.Parent
local styleType = {"Hair", "1"}

Button.MouseButton1Click:Connect(function()
	Event:FireServer(styleType)
end)

server script:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
local Character = nil
local style = nil
local humanoid = nil
local char = workspace:WaitForChild("CharSelectDummy")
Event.OnServerEvent:Connect(function(player, styleType)
	Character = player.Character or player.CharacterAdded:Wait()
	humanoid = char:WaitForChild("Humanoid")
	if styleType[1] == "Hair" then
		-- Hair types
		if (styleType[2] == "1") then
			style = player.PlayerGui.CharCreationScreen.HairScrollingFrame.ViewportFrame1.Hair:Clone()
			humanoid:AddAccessory(style)
		end
	end
end)

if the hat is an Accessory then just Parent it to the Character you want instead of using the AddAcesorry function. Also maybe create a folder in replicated will all your accessories and reference it from there instead of going all the way in the playergui.

You can, as long as that instance exists on both client and server. A part created on the client cant be sent to the server, and a part inside ServerStorage cant be sent to the client. An instance in Workspace being sent through a remote from the server would be received on the client.

1 Like

But why isn’t this working?

Doesn’t AddAccessory just parent? Probably wont work I think

1 Like

Yea didn’t work

-- Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")


local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
local Button = script.Parent
local styleType = {"Hair", "1"}

Button.MouseButton1Click:Connect(function()
	Event:FireServer(styleType)
end)
--Server script
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
local Character = nil
local style = nil
local humanoid = nil
local char = workspace:WaitForChild("CharSelectDummy")
Event.OnServerEvent:Connect(function(player, styleType)
	Character = player.Character or player.CharacterAdded:Wait()
	humanoid = char:WaitForChild("Humanoid")
	if styleType[1] == "Hair" then
		-- Hair types
		if (styleType[2] == "1") then
			style = player.PlayerGui.CharCreationScreen.HairScrollingFrame.ViewportFrame1.Hair:Clone()
			style.Parent = char
		end
	end
end)

Can you show an example of the accessory in-studio + send a video of what it looks like when the script is run??

https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory

Might be worth reading up on AddAccessory(), the BasePart instance named “Handle” inside the Accessory instance requires an Attachment instance inside of it matching the name of an Attachment instance inside the humanoid’s parent (character model), if these conditions are satisfied the BasePart instance is welded to the Attachment instance of the character model in such a way that both Attachment instances occupy the same space.

I did that here is a video showing everything: 2022 01 12 15 16 38 - YouTube

1 Like

Could you try this

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent1")
local Character = nil
local style = nil
local humanoid = nil
local char = workspace:WaitForChild("CharSelectDummy")
Event.OnServerEvent:Connect(function(player, styleType)
	Character = player.Character or player.CharacterAdded:Wait()
	humanoid = char:WaitForChild("Humanoid")
	if styleType[1] == "Hair" then
		-- Hair types
		if (styleType[2] == "1") then
			style = player.PlayerGui.CharCreationScreen.HairScrollingFrame.ViewportFrame1.Hair:Clone()
            style.Parent = game.ReplicatedStorage		
	        humanoid:AddAccessory(style)
		end
	end
end)
2 Likes