How do I instance a new part that everyone can see instead of Local Script?

So I was making an FPS game with some abilities in it, but then I started to find some problems that normal scripts can’t do but only Local Script. I tried to make it to a script so everyone on the server can see the part but then it doesn’t work. Can anyone please help me?

2 Likes

I believe this is the wrong category.

What do you mean it’s the wrong category?

This post is under the forum help category. I think it would fit better under the scripting support.

Ok, I will change it. But can you help me out?

I would recommend looking into remote events and remote functions. There are plenty of YouTube videos on it.

Thanks! I will try searching for some YouTube videos about it

Wait, I checked it. But all I see is AlvinBlox’s video and some Local Scripts

Keep looking and watch the whole video. If you want more information, create a topic under the correct category.

AlvinBlox’s video won’t help me because everytime I use his script it always fail

I can show you my script, can you help me fix it?

local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")

local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

userInputService.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.KeyCode == Enum.KeyCode.C then
		script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = true
		if script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.MouseButton1Click:Connect(function()
				local part = Instance.new("Part")
				part.Position = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector
				part.CFrame = CFrame.new(part.Position, humanoidRootPart.Position)
				part.Anchored = true
				part.CanCollide = true
				part.Parent = workspace
				part.Size = Vector3.new(20, 12, 4)
				part.BrickColor = BrickColor.new(0, 255, 255)
				script.Parent.MoveScript.Disabled = true
				script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
				script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = false
				script.Parent.StarterGui.MoveGUIS.PurchaseFrame.BuyIceWall.Avaible.Visible = false
			end) then
		end
	end
end)	

The output says that the character is not a valid member of player and I don’t know what to replace it or fix it

where is this script located in StartPlayerScripts?

Local Script

-- services

local userInputService = game:GetService("UserInputService")

local players = game:GetService("Players")

-- vars

local player = players.LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- remote

local event = game.ReplicatedStorage.Events.Barrier

-- detection

userInputService.InputBegan:Connect(function(input, gpe)

if gpe then return end

if input.KeyCode == Enum.KeyCode.C then

script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = true

if script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.MouseButton1Click:Connect(function()

event:FireServer()

end) then end

end

end)
    indent preformatted text by 4 spaces

Server Script

game.ReplicatedStorage.Events.Barrier.OnServerEvent:Connect(function(player)

local char = player.Character

local humanoidRootPart = char:WaitForChild("HumanoidRootPart")

local part = Instance.new("Part")

part.Position = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector

part.CFrame = CFrame.new(part.Position, humanoidRootPart.Position)

part.Anchored = true

part.CanCollide = true

part.Parent = workspace

part.Size = Vector3.new(20, 12, 4)

part.BrickColor = BrickColor.new(0, 255, 255)

script.Parent.MoveScript.Disabled = true

script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)

script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = false

script.Parent.StarterGui.MoveGUIS.PurchaseFrame.BuyIceWall.Avaible.Visible = false

end)

Watch The Video: ServerSided Barrier For JojoHuShenginMAL - YouTube

You have to use remote signals.

Remote signals are a good way to send a signal from the client, to the server. By using remotesignals, you can send a signal to the server to make the part for you so that it’s replicated for everyone to see. Here’s an example of how you could do it.

(If you’re using/testing this, don’t forget to change the remote variables to an actual remote.)

-- LocalScript
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local Remote -- Make this to your remote.

userInputService.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.KeyCode == Enum.KeyCode.C then
		script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = true
		if script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.MouseButton1Click:Connect(function()
				Remote:FireServer()
				script.Parent.MoveScript.Disabled = true
				script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
				script.Parent.StarterGui.MoveGUIS.UIFrame.CooldownFrame.HITBOX.Visible = false
				script.Parent.StarterGui.MoveGUIS.PurchaseFrame.BuyIceWall.Avaible.Visible = false
			end) then
		end
	end
end)
-- Server
local Remote -- Make the remote your remote.

Remote.OnServerEvent:Connect(function(Player)
    local Character = Player.Character
    local humanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

    local part = Instance.new("Part")
    part.Position = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector
    part.CFrame = CFrame.new(part.Position, humanoidRootPart.Position)
    part.Anchored = true
    part.CanCollide = true
    part.Parent = workspace
    part.Size = Vector3.new(20, 12, 4)
    part.BrickColor = BrickColor.new(0, 255, 255)
end)

You mean remote functions and events?

Well RemoteEvents I guess, they’re signals so I call them remotesignals.

Yes they are signals but don’t call them remote signals because no one will understand you

Thanks for all of you guy’s advice, it really helped a lot. Thank youuuuuu!!! :smiley: