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

Part Spawner only spawning parts in local workspace and not server workspace? HELLLPP

Asked by 2 years ago

So I am making a game with the main thing being a part spawning and the local script only spawns parts in the local players workspace MEANING only the player can see them and touch them and any other player in the server cant see them and i need to fix this and i need the parts to spawn server sided

The local script is located in StarterPlayerScripts and this is the script


local players = game:GetService("Players") local player = game.Players.LocalPlayer local mouse = player:GetMouse() local function Tar() local Materials = Enum.Material:GetEnumItems() -- Get a table of all the possible material local RandomMaterial = Materials[math.random(#Materials)] -- Select a random value inside the table wait() local Partt = Instance.new("Part") local S1 = math.random(1,5) local S2 = math.random(1,5) local S3 = math.random(1,5) Partt.Parent = game.Workspace Partt.Name = "RandomPart" Partt.Size = Vector3.new(S1,S2,S3) Partt.Position = mouse.Hit.Position Partt.Anchored = false Partt.CanCollide = true Partt.BrickColor = BrickColor.random() Partt.Material = RandomMaterial end mouse.Button1Down:Connect(Tar)

now one solution i thought of was making it a Normal Script and that would be perfect if only u could reference mouse with normal scripts but the mouse can only be referenced if its in a local script so im Really Stumped ive been waiting to discover or find a different aproach to this issue for maybe a week now and i really need help at this point

My Discord is bily117#5405 if u want to message me go ahead i accept all friend request if u wanna talk there i will also be checking this semi often so if u have a idea PLEASEEEEE tell me

0
The only solution to your problem lies in 'RemoteEvents'. Soban06 410 — 2y

1 answer

Log in to vote
0
Answered by
Soban06 410 Moderation Voter
2 years ago

Create a RemoteEvent in ReplicatedStorage. Name it 'CreatePart' Change the local script to this:

local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CreatePart = ReplicatedStorage:WaitForChild("CreatePart")


local function Tar()
    local Materials = Enum.Material:GetEnumItems() -- Get a table of all the possible material
    local RandomMaterial = Materials[math.random(#Materials)] -- Select a random value inside the table

    CreatePart:FireServer(mouse.Hit.Position, RandomMaterial)
end

mouse.Button1Down:Connect(Tar)

Now create a script inside 'ServerScriptService'. Name it anything you like. Put this in it:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CreatePart = ReplicatedStorage:WaitForChild("CreatePart")

CreatePart.OnServerEvent:Connect(function(player, mousePos, RandomMaterial)
  local Partt = Instance.new("Part")
    local S1 = math.random(1,5)
    local S2 = math.random(1,5)
    local S3 = math.random(1,5)
    Partt.Parent = game.Workspace
    Partt.Name = "RandomPart"
    Partt.Size = Vector3.new(S1,S2,S3)
    Partt.Position = mousePos
    Partt.Anchored = false
    Partt.CanCollide = true 
    Partt.BrickColor = BrickColor.random()
    Partt.Material = RandomMaterial
end)

Hope it helps.

Ad

Answer this question