I am making a localscript that spawns a part in a localplayer, But I am new to scripting and when I tested it out, other players didn't see the part, how can I fix it ? When I tried normal script it didn't work. The localscript is in Player's character, here is the script:
a = Instance.new("Part", workspace) a.Size = Vector3.new(50,10,50) a.Anchored = true a.Name = "corv" a.CanCollide = false a.Transparency = 0 a.Position = game.Players.LocalPlayer.Character.LowerTorso.Position
When you write code in a LocalScript
it only shows on your computer, not everyone else's.
If you want to show the part for everyone, you're going to have to create the part on the server. You can do this using remote events.
Here's how you'd to that:
1) Create a LocalScript
in the StarterPlayerScripts
2) Create a remote event in the ReplicatedStorage, call it createPartEvent
3) Put the following code in the localscript:
--reference the remote you made: local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent= ReplicatedStorage:WaitForChild("createPartEvent") -- Fire the remote event (tell the server you want to make a part) createPartEvent:FireServer()
3) Create a normal script in the ServerScriptService
4) Put the following code in the script:
--reference the remote event: local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent= ReplicatedStorage:WaitForChild("createPartEvent") -- function that creates a part --this function gets ran whenever the remote event is fired because --we have the code: "createPartEvent.OnServerEvent:Connect(createPart)" --which runs the function "createPart" whenever you say "createPartEvent:FireServer()" in a localscript. function createPart(player) --your code for creating the part is here: print(player.Name .. " fired the remote event") a = Instance.new("Part") a.Parent = workspace a.Size = Vector3.new(50,10,50) a.Anchored = true a.Name = "corv" a.CanCollide = false a.Transparency = 0 a.Position = player.Character.LowerTorso.Position end -- Call "createPart()" when a player fires the createPart remote event createPartEvent.OnServerEvent:Connect(createPart)
Let me know if you have any questions.
This youtube video explains remote events/remote functions fairly well
this is a wiki article on it if you prefer to read. They actually go over how to do what you're trying to do in the Client to Server
section of the article.
you can't
if you want to make a part visible to others, you have to create it on the server