Nothing coming in output with local script

So I made a local script here


and here is the script:

while true do
	local player = game.Players.LocalPlayer
	if player.MembershipType == Enum.MembershipType.Premium then
		script.Parent.Value = 1.25
		print(script.Parent.Value)
	else
		print(player..[[is not premium]])
	end
end

So the script is finding if the player is Premium, and if they are, then they get a 1.25 cash multiplier. But you may ask, “Why can’t you just put it in the leaderstats script?” Well, this is a tycoon, so… I can’t find a place to put it in there so yeah.

As said in my title, nothing seems to appear in the output. When it says obviously twice,

print(script.Parent.Value)
--and
print(player..[[is not premium]]

Why is this happening? Please respond.

3 Likes

Few things

  • Your while do loop has an expected iteration count of infinite, and so the main lua thread will be taken up by your loop if it is not closed. Basically means your game will “crash” (better term is to “hang indefinitely”)
  • Local scripts don’t run in workspace

Solutions:

  1. Add a wait in your while loop to prevent the game from hanging permantly.
  2. Put the LocalScript somewhere replicated to the client like StarterGui, StarterPlayerScripts (probably the best case in this scenario), StarterCharacterScripts, or ReplicatedFirst.
8 Likes

I dont know if this is the entirely the problem ( its likely not) but I’m pretty sure you cant concatenate the player “object” (If I remember correctly). I’m guessing you meant to concatenate the player's name.

1 Like

Do you mean:

print(player .." is not premium")

Is not printing in the console? or in the output? If it’s the console, then there are two buttons that you might see: Client/Server, click on Client and you might see the print.


@EpicMetatableMoment - Never, EVER, use wait() in that kind of circumstances:

2 Likes

I Dont think that he meant in the conditional part of the while loop statement itself while wait() do but inside the loop:
I think that he meant wait(n)

While true do 
  wait(...)
end

Edit: i realized that the thread linked was about wait()and flagging in specific but I still I think he meant wait(n) for the purpose of “waiting”

2 Likes

I meant the statement inside of the loop, not in the conditional.

But you’re still right, in this case it would be better to use something like player:GetPropertyChangedSignal("MembershipType") rather than looping until the membership type has changed.

1 Like

first LocalScripts dont work in the workspace.
second print(player..[[is not premium]]) needs to be print(player.." is not premium")
third you are using a while do loop and it has no timeout so the script will give out a script timeout error. try using a function instead.

1 Like

LocalScripts do not run when they are not parented to ReplicatedFirst, the player’s PlayerScripts, the players character, the player’s PlayerGui, and the player’s Backpack. Move the LocalScript somewhere else and make some additional changes within the script (because in this case, script.Parent will not work) and see what happens from there.

1 Like

Would I just do

function afunction()
end
--or
:Connect(function()
end)

?


Local scripts can run through all of those.
For example, a Local Script could be parented in ReplicatedFirst and be used to remove the DefaultLoadingScreen so you can place a Custom one.

Ok, i will try to give another help, i hope this help, this is not tested:

local player = game.Players.LocalPlayer
player.MembershipType.Changed:Connect(function()
--Rest of code
end)

That code will know if the player’s membership type has changed, if you want to know if the player already has premium, then create another local script and remove the Changed function.

He said ReplicatedFirst not ReplicatedStorage

You’re wrong.

LocalScripts can run in ALL of those and even more. Just open studio and test it if you don’t believe me.

@terrorpieyt you can’t run local scripts in ReplicatedStorage though, similarly to how scripts don’t run in ServerScriptStorage. Did you mean ReplicatedFirst?

Ah, yes that was a typo. I meant ReplicatedFirst. Fixing it now. Thank you for letting me know!

1 Like

I had said that LocalScripts do run when parented to the things I listed. ReplicatedFirst is the service that removes the default loading screen, not ReplicatedStorage. Nevermind, it was a typo.

You said, “do not run”. Guessing you made a simple typo?

I said they don’t run when they are not parented to what I listed.

1 Like

Yes both of them work but if youre using a variable to define the function dont forget to do

function afunction()
end
:Connect(afunction)

then you dont need to worry about the while loop

1 Like

This has kinda split into two. People are talking about the while loop, and others are talking about where the local script should be placed. So:

  • where should I place the local script? Should it be in StarterPlayerScripts?
    And
  • how to fix while loop? Use a function

Where to place localscripts: LocalScript | Documentation - Roblox Creator Hub

1 Like