Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't the server side remoteEvent detect objects?

Asked by 4 years ago

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!

3 answers

Log in to vote
1
Answered by
bum5Br 97
4 years ago

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.

0
ty Sensei_Developer 298 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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.

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

0
No no. I meant the server side was not working. Sensei_Developer 298 — 4y
0
ok JesseSong 3916 — 4y
0
No. I have a localScript inside the startergui, and a serverscript inside the serverscriptservice. The remote event listener in the serverscriptservice is not picking up the object value of "clone" and just throws and error saying "nil" Sensei_Developer 298 — 4y
0
hmmm JesseSong 3916 — 4y

Answer this question