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

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

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" :(

22 comments

0

the script is inside the textlabel btw

0

PlayerAdded is server side only.

0

PlayerAdded is only for in-game?

0

You shouldn’t be using it in a LocalScript^

0

how do you access local players from a server side script? the same when using a localscript?

0

No. You can access the player using PlayerAdded, OnServerEvent, MouseClick, etc.

0

so what do you want to do, change the text each time a player joins or each time a player spawns?

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?

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.

0

game.Players.PlayerAdded:Connect(function(player) print(player.Name) end)

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)

0

So you want all players to see "jaja"?

0

i want the certain player to see "jaja" on his gui

0

who is the certain player?

0

you want all players to see "jaja" whenever they initially join?

0

Accidently added the answer :P

0

yes wait i will update with full code

0

You’re using LocalPlayer from the server.

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

0

i updated my answer

0

i tried script.Parent.Parent.Parent everything works besides the playeradded functions

0

read the edit in my answer

1 answer

✓ Accepted answer

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()

5 comments

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)

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?

0

You should call it currentexpcalculate somewhere else then

0

nvm fixed it, i used characteradded instead of playeradded xD thanks.

0

glad to hear

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