I was creating a building system, and I wanted to make the placement server-sided, so I added a remote event into ReplicatedStorage
and had this portion of a LocalScript
typed up:
(it's specificly this part that isnt working)
function placeItem() local place = clone:Clone() place.Parent = workspace place.PrimaryPart.Transparency = 0 place.PrimaryPart.CanCollide = true end mouse.Button1Down:Connect(function() game.ReplicatedStorage.PlaceItem:FireServer(clone) end)
then, I made a ServerScript
in the ServerScriptService
and typed up:
game.ReplicatedStorage.PlaceItem.OnServerEvent:Connect(function(player,clone) local place = clone:Clone() place.Parent = workspace place.PrimaryPart.Transparency = 0 place.PrimaryPart.CanCollide = true end)
However, it keeps saying that the clone in the serverscript is nil. I clearly defined the object, but it's not detecting it.
What on earth??!! Help please!
You created a clone in the Client's side, which can't be viewed by the server, giving you nil as a result. Try getting the original part from the local script and then cloning it on the server side.
The reason why is because the client is creating a clone. This makes the cloned object only on the client's side. When sending that cloned object to the server, its gonna end up being nil because it's not replicated on the server. The server would have to use the original object. The server can only work with things that are already on the server. So if the client makes or clones an object that object will only be on the client's side.
I think the reason it didn't work was because you didn't put :FireClient() And you need to connenct the remote event to FireClient()
Also I haven't tested the script. So I might be wrong.