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

It won't change the gui's text when the player joins and respawns. Help please?

Asked by 4 years ago

Okay so i have this script and with some pretty simple code right, WRONG, it won't work when someone joins/respawns. No output telling why, just like- Help please?

--Script
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Wait(function(char)
        for i = 1,20 do
            local text = plr:WaitForChild('PlayerGui'):FindFirstChild('ScreenThings'):FindFirstChild('ShowingMoneyFrame'):FindFirstChild('HonksText')
            text.Text = 'Honks: '.. plr:FindFirstChild('leaderstats'):FindFirstChild('Honks').Value
            wait(1)
        end
    end)
end)
0
What's the goal You want it to do for beside changing the text? S0NIC_Dev 61 — 4y
0
Use a local script in the screen gui XviperIink 428 — 4y
1
The Wait method of the RBXScriptSignal base class does not accept callbacks, only a timeout; the Character Instance is only added after death, upon joining the CharacterAdded event will not fire. Ziffixture 6913 — 4y
0
lol im done with this but im just confused why nobody is questioning the currency name? im sure yall see some weird stuff on here but 'Honks' Is very odd- XD Galaxybombboy 134 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

Excuse my ignorance on the matter, as I haven't actually done anything in Studio for a good year. I can't remember if the server can make changes to the PlayerGui, although I thought they could. As such, I'll provide a server and a local option.

Ziffxture was correct, you should not be using .CharacterAdded:Wait(). Instead, you should simply connect it to a function, as you did with .PlayerAdded.

Server

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        for i = 1,20 do
            local text = plr:WaitForChild('PlayerGui'):FindFirstChild('ScreenThings'):FindFirstChild('ShowingMoneyFrame'):FindFirstChild('HonksText')
            text.Text = 'Honks: '.. plr:FindFirstChild('leaderstats'):FindFirstChild('Honks').Value
            wait(1)
        end
    end)
end)

Local

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

Player.CharacterAdded:Connect(function(Character)
    for i = 1,20 do
        local text = Player:WaitForChild('PlayerGui'):FindFirstChild('ScreenThings'):FindFirstChild('ShowingMoneyFrame'):FindFirstChild('HonksText')
        text.Text = 'Honks: '.. Player:FindFirstChild('leaderstats'):FindFirstChild('Honks').Value
        wait(1)
    end
end)

So there are two options, keeping in mind that the LocalScript will have to be placed appropriately.

I also do not recommend using so many :FindFirstChild()s. In the first place, their usage in your case is completely irrelevant. The point of using the method is to make sure an instance exists before you attempt to interact with it, thus avoiding the dreaded attempt to index a nil value error. However, in your line of code immediately after declaring the variable text, you're trying to changing the Text property of the instance. This means that if, for some reason, the instance did not exist, you would be indexing a nil value, nullifying the purpose of your usage of :FindFirstChild(). To solve this, or rather make it more helpful, use a simple if statement.

local Object = workspace:FindFirstChild("Object")

if Object then
    Object.Name = "Found!"
end
Ad

Answer this question