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

local script doesn't change a textlabel text but doesnt show any errors?

Asked by 5 years ago
Edited 5 years ago
local Players = game:GetService("Players")
function starter()
    wait(1)
    script.Parent.Text = "jaja"
end

game.Players.PlayerAdded:connect(starter)


both in-game, in studio and in local server

FULL CODE

--FULL CODE INSIDE GUI, PUT IT IN A SERVER SIDE SCRIPT BUT PLAYER ADDED FOR CURRENTEXP CALCULATE AND GIVELEVEL STILL DOESNT WORK--
local owner = game.Players.LocalPlayer
local ownerStats = owner.Stats
local currentExp = 100
local var = 1
local expNeeded

function onLevel()
    ownerStats.Value = ownerStats.Value+3
    ownerStats.Defense.Value = ownerStats.Defense.Value+1
    ownerStats.Strength.Value = ownerStats.Strength.Value+1
    ownerStats.Vitality.Value = ownerStats.Vitality.Value+1
    ownerStats.Agility.Value = ownerStats.Agility.Value+1
    ownerStats.Dexterity.Value = ownerStats.Dexterity.Value+1
    ownerStats.Intelligence.Value = ownerStats.Intelligence.Value+1
end

function currentexpCalculate()
    while var <= ownerStats.Lvl.Value do
        currentExp = currentExp*(1+(.20))
        var = var+1
    end
    expNeeded = currentExp
    if ownerStats.Exp.Value <= expNeeded then
        owner.PlayerGui.mainUI.Frame.expHolder.expBar:TweenSize(UDim2.new(ownerStats.Exp.Value/expNeeded, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle. Linear, 0.1)
    end
end

function expChanged()
    currentexpCalculate()
    if ownerStats.Exp.Value >= expNeeded then
        while ownerStats.Exp.Value >= expNeeded do
            ownerStats.Exp.Value = ownerStats.Exp.Value-expNeeded
            ownerStats.Lvl.Value = ownerStats.Lvl.Value+1
            onLevel()
        end
    end
end

function runThis()
    owner.PlayerGui.mainUI.Frame.expHolder.expBar:TweenSize(UDim2.new(ownerStats.Exp.Value/expNeeded, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle. Linear, 0.1)
    owner.PlayerGui.mainUI.Frame.pictureHolder.levelHolder.Text = ownerStats.Lvl.Value
end

function giveLevel()
    print("lmao")
    script.Parent.Parent.mainUI.Frame.pictureHolder.levelHolder.Text = owner.Character.Name
end

game.Players.PlayerAdded:Connect(giveLevel)
game.Players.PlayerAdded:Connect(currentexpCalculate)
ownerStats.Exp.Changed:Connect(expChanged)
ownerStats.Lvl.Changed:Connect(runThis)

IT DOESNT EVEN PRINT "LMAO" :(

0
the script is inside the textlabel btw xxXTimeXxx 101 — 5y
0
PlayerAdded is server side only. User#19524 175 — 5y
0
PlayerAdded is only for in-game? cherrythetree 130 — 5y
0
You shouldn’t be using it in a LocalScript^ User#19524 175 — 5y
View all comments (18 more)
0
how do you access local players from a server side script? the same when using a localscript? xxXTimeXxx 101 — 5y
0
No. You can access the player using PlayerAdded, OnServerEvent, MouseClick, etc. User#19524 175 — 5y
0
so what do you want to do, change the text each time a player joins or each time a player spawns? Elixcore 1337 — 5y
0
when a player joins. however that piece of info that playeradded can only be used in serverside helps my game a lot since i mostly rely on localscripts lmao. so how do i find the player in workspace players in a serverside script? xxXTimeXxx 101 — 5y
0
Clarify what you are trying to do and I will post a response. Are you trying to change it to something different each time a new player spawns, or are you just trying to set the text initially, and that is a constant value like in your script? Edit your question to clarify. amanda 1059 — 5y
0
game.Players.PlayerAdded:Connect(function(player) print(player.Name) end) amanda 1059 — 5y
0
i want to change it once just when a player joins since its supposed to be a level display script for an rpg game (i want the loaded level to display on spawn) xxXTimeXxx 101 — 5y
0
So you want all players to see "jaja"? amanda 1059 — 5y
0
i want the certain player to see "jaja" on his gui xxXTimeXxx 101 — 5y
0
who is the certain player? amanda 1059 — 5y
0
you want all players to see "jaja" whenever they initially join? amanda 1059 — 5y
0
Accidently added the answer :P cherrythetree 130 — 5y
0
yes wait i will update with full code xxXTimeXxx 101 — 5y
0
You’re using LocalPlayer from the server. User#19524 175 — 5y
0
it works with the other parts of the script, just not on playeradded, how would i find the individual player's gui without localplayer? :o xxXTimeXxx 101 — 5y
0
i updated my answer amanda 1059 — 5y
0
i tried script.Parent.Parent.Parent everything works besides the playeradded functions xxXTimeXxx 101 — 5y
0
read the edit in my answer amanda 1059 — 5y

1 answer

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
5 years ago
Edited 5 years ago

The issue you are most likely facing, is that the player is already loaded, so it will not trigger the PlayerAdded event.

It will only fire locally for them for all players who join after they do.

--

To solve this, remove the whole function and just run the contents at the top of the LocalScript, because the LocalScript runs when the player joins.

Entire script:

script.Parent.Text = "jaja"

However, if you are doing this, you might as well just configure the Text to be this in the StarterGui without a script at all, in order to set the default/initial text.

Please update your question with additional information if this did not solve your problem.

EDIT:

If you just want giveLevel and currentexpCalculate to run whenever the player initially joins, keep it in a LocalScript, and just call both of them after you've defined everything else.

--your entire new script you posted

--the bottom of it
giveLevel()
currentexpCalculate()
0
currentexpcalculate would run everytime the player levels since it increases the exp needed to level by 20%. While givelevel is the one that is supposed to change the text in the gui to the level of the player on player join(added) xxXTimeXxx 101 — 5y
0
You had both connected to PlayerAdded events, so my assumption was you wanted both to run. I am not going to write your whole script for you. Tell me that givelevel doesn't run when they join now? amanda 1059 — 5y
0
You should call it currentexpcalculate somewhere else then amanda 1059 — 5y
0
nvm fixed it, i used characteradded instead of playeradded xD thanks. xxXTimeXxx 101 — 5y
0
glad to hear amanda 1059 — 5y
Ad

Answer this question