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

What's wrong that makes this code not work?

Asked by 10 years ago

I have the following code that does not do what I want. I want to make it so that for every player, an announcement shows up letter by letter, just like Daxter33's Paintball! announcements. I tried this but wont work, no errors too.. Could someone help me please?

Players = game.Players:GetChildren()
function Deathmatch()
    wait(2)
    Time = 5
    for i = 1,#Players do
        String = "Round Chosen: Deathmatch"
        for b = 1,#String do
        Players[i].Backpack.GameHint.TextLabel.Text = Players[i].Backpack.GameHint.TextLabel.Text..String:sub(b)
        wait(.2)
        end
    end
end
game.Players.PlayerAdded:connect(Deathmatch)

2 answers

Log in to vote
1
Answered by 10 years ago

Recheck your code, and you'll find a few mistakes; You are using the 'GetChildren' method, but you may be wondering, 'what is wrong with that?', well, if there was a 'Hat' type instance in 'Players', GetChildren will count the hat aswell, let's try using the 'GetPlayers' instead. :)

local Players = game.Players:GetPlayers() --The 'GetPlayers' method gets all current 'Player' type instances that is in 'Players', so if there were to be a 'Hat' instance, it would return as 'nil'

function Deathmatch()
wait(2)
local Time = 5 --What is 'Time' used for?
for i,v in pairs(Players) do --Ya, I switch out your old 'for' loops with a more efficient one :)
if v then --Check if 'Player' is existant
String = "Round Chosen: Deathmatch"
for i2,v2 in pairs(String) do
if v:FindFirstChild("PlayerGui") and v.PlayerGui:FindFirstChild("GameHint") and v.PlayerGui.GameHint:FindFirstChild("TextLabel") then --Checks to see if 'PlayerGui', 'GameHint', and 'TextLabel' are existant within 'Player'
v.PlayerGui.GameHint.TextLabel.Text = v2:sub(1,i) --Ah, now doesn't this look much better? :)
end
wait(1/19)
end
end
end
end

game.Players.PlayerAdded:connect(Deathmatch) --Connects the function 'Deathmatch' to the event; fires when a Player joins
for i,v in pairs(Players) do Deathmatch() end --The 'PlayerAdded' event does not work in Studio mode, so you use this :)

Also, GUIs do not show up in the 'Backpack', they show up only in the Player's 'PlayerGui', 'SurfaceGui', or 'BillboardGui', which is why I switch your code from Backpack to PlayerGui. Hope this helped!

0
Somehow still doesn't work?? I'm also a little annoyed with Studio not working properly fahmisack123 385 — 10y
0
I could also need your help for another problem I'm facing. Here's the Model: http://www.roblox.com/Needs-Fixing-item?id=193678341 fahmisack123 385 — 10y
Ad
Log in to vote
-2
Answered by
modFrost 130
10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Alright, I will fix your code up for you just to make it work, good luck!

local Players = game:GetService("Players"):GetPlayers()
function Deathmatch()
    wait(2)
    Time = 5
    for _,Player in pairs(Players) do
        local String = "Round Chosen: Deathmatch"
        for i = 1,#String do
            Player.Backpack.GameHint.TextLabel.Text = tostring(String:sub(1, i))
            wait(0.2)
        end
    end
end
game:GetService("Players").PlayerAdded:connect(Deathmatch)
0
Didn't work fahmisack123 385 — 10y

Answer this question