What do i want to achieve? A Selection system like i Block n’ props (You will prob understand after seeing the script)
Like this:
local Props = game.ReplicatedStorage.Props:GetChildren()
local Add = script.Parent.AddPart.CD
local Remove = script.Parent.RemovePart.CD
local SpawnButton = script.Parent.SpawnPart.CD
local DisplayText = script.Parent.DisplayPart.DisplayGui.Text
local SelectedProp = 1
Add.MouseClick:Connect(function()
if SelectedProp == 1 then
if Props[SelectedProp]:FindFirstChildWhichIsA("Part") then
SelectedProp += 1
SpawnButton.MouseClick:Connect(function()
local Part = Props[SelectedProp]:FindFirstChildWhichIsA("Part"):Clone()
Part.Parent = workspace
end)
end
end
end)
Remove.MouseClick:Connect(function()
end)
while true do
task.wait()
end
Hello. There are several issues with this code, but you have the right gist on everything.
while true do
task.wait()
end
Please do not use this. There is no reason for you to do that.
Secondly, you are using a Local Script, and attempting to spawn a part like that. This will work, although the part will only appear for the client, not for anyone else.
To circumvent this, you can use a RemoteEvent that the client fires, and the server responds by spawning that part in. You could probably also set the CFrame of the part
Here is an example
-- Localscript
local SelectedProp = 1
Add.MouseClick:Connect(function()
end) -- Do not do many if statements. It's inefficient
Remove.MouseClick:Connect(function()
end) -- Do not do many if statements. It's inefficient
local RemoteEvent = ReplicatedService:FindFirstChild("SpawnPart") -- RemoteEvent
SpawnButton.MouseClick:Connect(function()
RemoteEvent:FireServer(SelectedProp)
end)
-- ServerScript
local RemoteEvent = ReplicatedStorage:FindFirstChild("SpawnPart")
RemoteEvent.OnServerEvent:Connect(function(playerWhoFired, SelectedProp)
local Part = Props[SelectedProp]:FindFirstChildWhichIsA("Part"):Clone()
Part.Parent = workspace
Part.Position = playerWhoFired.Character.HumanoidRootPart.Position + Vector3.new(2,0,0)
end)
-- You can change this to be a model, but by doing that you'll have to change the Model.PrimaryPart.