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 6 years ago
Edited 6 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

01game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player)
02print("Works!")
03CA = game.ReplicatedStorage.CreateAmount.Value
04    for i = 1, CA do
05    wait(0.2)
06local deathPart = game.ReplicatedStorage.F9
07wait(0.2)
08local F9C = deathPart:Clone()
09wait(0.2)
10F9C.Parent = game.workspace.F9Parent
11F9C.Position = Vector3.new(math.random(-590,-460), 57, math.random(-170,60))
12end
13end)

Local Script

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

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 — 6y
0
No. Gameplay28 139 — 6y

1 answer

Log in to vote
1
Answered by
farizarps 132
6 years ago
Edited 6 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

01game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player, CA)
02    print("Works!")
03    for i = 1, CA do
04        wait(0.2)
05        local deathPart = game.ReplicatedStorage.F9
06        wait(0.2)
07        local F9C = deathPart:Clone()
08        wait(0.2)
09        F9C.Parent = game.workspace.F9Parent
10        F9C.Position = Vector3.new(math.random(-590,-460), 57, math.random(-170,60))
11    end
12end)

Client

1script.Parent.MouseButton1Click:Connect(function()
2    script.Parent.Text = game.Players.LocalPlayer:WaitForChild("PlayerGui").ScreenGui3.TextBox.Text
3    game.ReplicatedStorage.CreateEvent:FireServer(script.Parent.Text)
4    end
5end)
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 — 6y
0
oh sorry it should be :FireServer() farizarps 132 — 6y
0
It almost works now, however it spawns an limitless amount with no time between Gameplay28 139 — 6y
0
its because of the while loop farizarps 132 — 6y
Ad

Answer this question