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
01 | game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect( function (player) |
02 | print ( "Works!" ) |
03 | CA = game.ReplicatedStorage.CreateAmount.Value |
04 | for i = 1 , CA do |
05 | wait( 0.2 ) |
06 | local deathPart = game.ReplicatedStorage.F 9 |
07 | wait( 0.2 ) |
08 | local F 9 C = deathPart:Clone() |
09 | wait( 0.2 ) |
10 | F 9 C.Parent = game.workspace.F 9 Parent |
11 | F 9 C.Position = Vector 3. new(math.random(- 590 ,- 460 ), 57 , math.random(- 170 , 60 )) |
12 | end |
13 | end ) |
Local Script
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | while true do |
3 | game [ "Run Service" ] .RenderStepped:wait() |
4 | script.Parent.Text = game.Players.LocalPlayer:WaitForChild( "PlayerGui" ).ScreenGui 3. TextBox.Text |
5 | game.ReplicatedStorage.CreateAmount.Value = script.Parent.Text |
6 | end |
7 | end ) |
Even if I change the Number Value in develop mode, it still doesn't spawn any parts and only prints "Works!" once.
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
01 | game.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.F 9 |
06 | wait( 0.2 ) |
07 | local F 9 C = deathPart:Clone() |
08 | wait( 0.2 ) |
09 | F 9 C.Parent = game.workspace.F 9 Parent |
10 | F 9 C.Position = Vector 3. new(math.random(- 590 ,- 460 ), 57 , math.random(- 170 , 60 )) |
11 | end |
12 | end ) |
Client
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | script.Parent.Text = game.Players.LocalPlayer:WaitForChild( "PlayerGui" ).ScreenGui 3. TextBox.Text |
3 | game.ReplicatedStorage.CreateEvent:FireServer(script.Parent.Text) |
4 | end |
5 | end ) |