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

Script not creating the amount of parts that I want it to?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a gui so that when you click it, an amount of parts spawn.

I also have a gui to determine how many parts to spawn, this is where I'm stuck.

Server Script

game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player)
print("Works!")
CA = game.ReplicatedStorage.CreateAmount.Value
    for i = 1, CA do
    wait(0.2)
local deathPart = game.ReplicatedStorage.F9
wait(0.2)
local F9C = deathPart:Clone()
wait(0.2)
F9C.Parent = game.workspace.F9Parent
F9C.Position = Vector3.new(math.random(-590,-460), 57, math.random(-170,60))
end
end)

Local Script

script.Parent.MouseButton1Click:Connect(function()
    while true do
    game["Run Service"].RenderStepped:wait() 
script.Parent.Text = game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui3.TextBox.Text
game.ReplicatedStorage.CreateAmount.Value = script.Parent.Text 
end
end)

Even if I change the Number Value in develop mode, it still doesn't spawn any parts and only prints "Works!" once.

0
Are there any errors? captain_bboy 22 — 5y
0
No. Gameplay28 139 — 5y

1 answer

Log in to vote
1
Answered by
farizarps 132
5 years ago
Edited 5 years ago

ReplicatedStorage is on the server and replicated to every client. Client-Server Model

the line: game.ReplicatedStorage.CreateAmount.Value = script.Parent.Text changes the value of CreateAmount on the players' computer and not the actual server so the server will always make the default number.

I suggest that you simply send the amount you want to be created as an argument in the remote event.

Server

game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player, CA)
    print("Works!")
    for i = 1, CA do
        wait(0.2)
        local deathPart = game.ReplicatedStorage.F9
        wait(0.2)
        local F9C = deathPart:Clone()
        wait(0.2)
        F9C.Parent = game.workspace.F9Parent
        F9C.Position = Vector3.new(math.random(-590,-460), 57, math.random(-170,60))
    end
end)

Client

script.Parent.MouseButton1Click:Connect(function() 
    script.Parent.Text = game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui3.TextBox.Text
    game.ReplicatedStorage.CreateEvent:FireServer(script.Parent.Text) 
    end
end)

0
I tried your scripts, but it still doesn't work, I did get an error in the output though "Fire is not a valid member of RemoteEvent".. Gameplay28 139 — 5y
0
oh sorry it should be :FireServer() farizarps 132 — 5y
0
It almost works now, however it spawns an limitless amount with no time between Gameplay28 139 — 5y
0
its because of the while loop farizarps 132 — 5y
Ad

Answer this question