Hey all, I recently dug up a stamper tool I made a few years back and touched it up a little bit. It inserts an object wherever you want by cloning it from ReplicatedStorage and inserting it into the workspace. That all works fine, but the problem starts when playing with friends... we're unable to see each other's creations, they're all client-sided (I guess) so we can only see what we built ourselves.
I've done a bit of reading on RemoteEvents and RemoteFunctions (though I'm not sure which of the two to use), and I'm a little rusty, having not coded in over a year. Before I continue to attempt to learn that, however, are there any other ways I'd be able to fix the problem about? Just looking to explore my options :)
RemoteFunctions return a value, RemoteEvents are a signal from server to client, client to server.
--LocalScript in a tool local plr = game.Players.LocalPlayer local stamp = script.Parent local mouse = plr:GetMouse() local event = game.ReplicatedStorage:WaitForChild("EventNameHere") stamp.Activated:Connect(function() local mouse_pos = mouse.Hit.p -- mouse.Hit is a CFrame local selected --Assign selected to something event:FireServer(mouse_pos, selected) end) --In a ServerScript local event = game.ReplicatedStorage:WaitForChild("EventNameHere") event.OnServerEvent:Connect(function(plr, position, modelName) local object = game.ReplicatedStorage:FindFirstChild(ModelName) if object then object = object:Clone() object.MainPart.Position = position --Assign a MainPart to the model instance, weld all parts inside the model to the main part end end)
The only way I know are remote events. They seem a little confusing but here is the gist of them:
So our remote event, "createPart", will be stored in ReplicatedStorage. All we need to do is set up a listener for when the event fires:
local ReplicatedStorage = game:GetService("ReplicatedStorage") ReplicatedStorage.createPart.OnServerEvent:Connnect(function(plr, partToBeCreated) local ws = game.Workspace local part = Instance.new(partToBeCreated) part.Parent = ws end)
Now when we fire the event, that piece of code will run. To make the event fire, we do this:
local tool = script.Parent tool.Activated:Connect(function() game.ReplicatedStorage.createPart:FireServer("Part") end)
Now when our player clicks with the tool out, our remote event will fire using FireServer.
If you haven't seen my comment, do so now. Anyways, if you need help with remote events and remote functions, here are roblox API refferences on those:
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
https://developer.roblox.com/en-us/api-reference/class/RemoteFunction
LOCAL SCRIPT or something along the lines of this:
mouse clicked
local typeOfBlock = (the selected block) local mouse.Target.Position
game.ReplicatedStorage.Event:FireServer(typeOfBlock, mousePos)
SERVER SCRIPT
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(typeOFBlock, mousePos) --placement script goes here end)
hope that helps how to go about this, I normally dont do scripting to answer peoples questions because I dont think people learn how to script by copy and pasting, and I don't always have enough details to help you with the actual scripting and variables and such. I hope you actually LEARN from this! Hope this helps!