in a Script in ServerScriptStorage
It's supposed to fire to a client giving the name of the model so that the other script can clone the model from the name and place it.
local remotevents = game.ReplicatedStorage.RemoteEvents local partplacer = remotevents.PartPlacer partplacer.ShowPart.OnServerEvent:connect(function(plr,modelName) partplacer.ShowPart:FireClient(modelName) end);
This is the client |v|
local model = game.ReplicatedStorage.Model local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local PartPlacerModel = game.ReplicatedStorage.RemoteEvents.PartPlacer local function updatePart(model) model:SetPrimaryPartCFrame(CFrame.new(math.floor(mouse.Hit.p.X),0.5,math.floor(mouse.Hit.p.Z))) end; mouse.KeyDown:connect(function(key) if key == "e" then PartPlacerModel.ShowPart:FireServer(model.Name) -- Firing the ModelName end; end); PartPlacerModel.ShowPart.OnClientEvent:connect(function(plr, modelName) local model = game.ReplicatedStorage:FindFirstChild(tostring(modelName)) if model then local newModel = model:Clone() newModel.Parent = game.Workspace mouse.Move:connect(function() updatePart(newModel) end); end; end);
Hey TheShiningSavior,
Two problems immediately apparent with this script are that you do not provide a player to FireClient
on line 5 of the server script, and that you have an argument plr
on line 19 of the client script. The problems with these things, respectively, are that:
When you call FireClient, you have to specify who you want to affect, like so: FireClient(plr, ...)
OnClientEvent does not supply a player, because you should already know who the player is: you could retrieve that with game.Players.LocalPlayer
in any LocalScript
. Because a player is not provided, the model name is actually supplied to plr
, and modelName
would be nil
.
It's also worth noting that you're moving the model on line 9 of the client script. You should never move parts or models with a local script, because this will immediately stop being replicated to other clients if filtering is enabled. You should instead do this in the server script.
I hope this helps. Have a nice day, TheShiningSavior, and best of luck with your game!
Best regards,
tkcmdr
Sources: