Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

Are there any errors?

0

No.

1 answer

✓ Accepted answer

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)

4 comments

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"..

0

oh sorry it should be :FireServer()

0

It almost works now, however it spawns an limitless amount with no time between

0

its because of the while loop

This discussion is preserved as it was. New answers, comments, and votes are closed.