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

How do I fix this so I could have the number displaying?

Hello I had a problem with the text not showing up in the UI. This is my script and I will give you more details

local part = game.Workspace.Generator
local NumBlocks = game.StarterGui.ScreenGui.NumBlocks
local User = NumBlocks.Parent.User
local Rating = NumBlocks.Parent.Rating
local IntValue = Instance.new("IntValue", game.ReplicatedStorage)
wait(3)
while true do
	local LagPart = Instance.new("Part", game.Workspace)
	LagPart.CFrame = LagPart.CFrame * part.CFrame
	--LagPart.Transparency = 1
	IntValue.Value = IntValue.Value + 1
	NumBlocks.Text = (IntValue.Value)
	print(IntValue.Value)
	wait(0.000000000000000000000000000000000000001)
end

So basicly when I run the game I can see how many parts are there. But when I play the script so playing the game the Number of parts don't show up...How do I fix this? This is a script in server script service. Thanks

2 comments

0

There is no need to do wait(0.00000000000000000000001), just do wait()

0

ok

4 answers

✓ Accepted answer

Hello, there is a solution to your problem, look at the comments on the script!:

--ServerScript
local part = game.Workspace.Generator
local User = NumBlocks.Parent.User
local Rating = NumBlocks.Parent.Rating
local IntValue = Instance.new("IntValue", game.ReplicatedStorage)
wait(3)
while true do
 
    local LagPart = Instance.new("Part", game.Workspace)
    LagPart.CFrame = LagPart.CFrame * part.CFrame
    --LagPart.Transparency = 1
    IntValue.Value = IntValue.Value + 1
    for i, plr in pairs(game.Players:GetChildren()) do --Loop through all the players in-game
	    plr.PlayerGui.ScreenGui.NumBlocks.Text = (IntValue.Value)
	    print(IntValue.Value)
	    wait()
    end
end

Basically, all that I fixed was that I looped through all the players gui's, and I changed the test to IntValue.Value. Hope It Helps

1 comment

0

User and Rating are no longer valid according to your changes

If you are talking about how many parts you will see in the game then you could use the Clone() function

2 comments

0

Theres no need to clone when you could instance a part.

0

So what I was asking is how do you display or how do you fix how many partd sre there

local part = game.Workspace.Generator
local ScreenGui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
        local NumBlocks = ScreenGui:WaitForChild("NumBlocks")
        local User = ScreenGui:WaitForChild("User")
        local Rating = ScreenGui:WaitForChild("Rating")

        NumBlocks.Text = tostring(IntValue.Value)
-- and make sure you use playergui since it Will get cloned when the player has loaded
local User = NumBlocks.Parent.User
local Rating = NumBlocks.Parent.Rating
local IntValue = Instance.new("IntValue", workspace) -- intvalues don't run in replicated storage so change it to workspace.
wait(3)
while true do
wait (1)
    local LagPart = Instance.new("Part", game.Workspace)
    LagPart.CFrame = LagPart.CFrame * part.CFrame
    --LagPart.Transparency = 1
    IntValue.Value = IntValue.Value + 1
    NumBlocks.Text = (IntValue.Value)
    print(IntValue.Value)
end
end

2 comments

0

Sorry how do change it to playerGui?

0

Edited

Improvements

Use :GetService() for services such as ReplicatedStorage and StarterGui

Set the Parent of a new Instance on a separate line as the run-time is more efficient that way

Use :WaitForChild() to make sure an instance exists before using it

Issues

You are attempting to edit the NumBlocks in the StarterGui, but players have a separate PlayerGui instance where the Guis on their screen are found.

Revised Server Script

local part = game:GetService("Workspace"):WaitForChild("Generator")
local IntValue = Instance.new("IntValue")
IntValue.Parent = game:GetService("ReplicatedStorage")
wait(3)

while true do
	local LagPart = Instance.new("Part")
	LagPart.Parent = game:GetService("Workspace")
	LagPart.CFrame = LagPart.CFrame * part.CFrame
	-- LagPart.Transparency = 1

	IntValue.Value = IntValue.Value + 1
	for index, player in pairs(game:GetService("Players"):GetPlayers()) do
		local ScreenGui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
		local NumBlocks = ScreenGui:WaitForChild("NumBlocks")
		local User = ScreenGui:WaitForChild("User")
		local Rating = ScreenGui:WaitForChild("Rating")
		
		NumBlocks.Text = tostring(IntValue.Value)
	end
	
	print(IntValue.Value)
	wait()
end

1 comment

0

You don't have to, trust me.....

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