I have remote event, but it send only player and not the parametr that i need
client:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
createPartEvent:FireServer(clone)
server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
createPartEvent.Name = "CreatePartEvent"
function create (player, part)
part.Parent = workspace.players
end
createPartEvent.OnServerEvent:Connect(create)
I would recommend not sending an object as the parameter, but an object name. That way you can see exactly what it needs to clone and do everything on the server side.
Yes I think it should work like that. Because basically you are parenting a clone and it should be correct. And I would agree with @Chrythm because RemoteEvents are mostly used for exchanging with parameters and values. I hope this helps.
By having the event add any object that the client sends, you are leaving a backdoor for anyone who has a hacked client. Send the name of the skin instead of the skin object.
Before you do any change in scripts give the object you’d like to clone in ServerStorage. From my prespective it should be something like this in a client:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
createPartEvent:FireServer(clone.Name) -- Sends a name of an object and fires server
And on server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage) -- Creates Event
createPartEvent.Name = "CreatePartEvent" -- Sets name of Event
function create (player, part)
local Object = game.ServerStorage:FindFirstChild(part):Clone() -- Clones object from ServerStorage
Object.Parent = workspace.players -- Sets a Parent of cloned object
end
createPartEvent.OnServerEvent:Connect(create) -- OnServerEvent Fired
Based on @Chrythm’s answer, I used a similar method for my game.
For my game, I had an items folder in ReplicatedStorage. Since it’s a sandbox game, I had an event and two scripts. One server script in ServerScriptService and another in StarterGui.
-- LocalScript
local replicatedStorage = game:GetService("ReplicatedStorage")
local items = replicatedStorage:WaitForChild("items")
local event = replicatedStorage:WaitForChild("Place")
-- Apply the skin to a player.
function applySkin(skin)
event:FireServer(skin)
end
-- Give the player a skin, I don't know.
applySkin("Crystal")
Then in a server script, you can handle it however you want.
-- Script
local replicatedStorage = game:GetService("ReplicatedStorage")
local items = replicatedStorage:WaitForChild("items")
local event = replicatedStorage:WaitForChild("Place")
event.OnServerEvent:Connect(function(plr, item)
-- Apply skin to a gun?
local backpack = plr:WaitForChild("Backpack")
local gun = backpack:WaitForChild("Glock") -- Or whatever. You should be able to make it work.
local template = items:FindFirstChild(item)
if(template ~= nil) then
local item = template:Clone()
item.Parent = gun -- ?
end
end)
I don’t know exactly what you’re trying to do, but you could work with this example and probably do some awesome things with it.