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

Why won't my mesh's transparency turn to 0 if value is bigger than zero?

Hi. Okay, so, I am making a questing system and this is the only way that I can think of doing.

My leaderstats are saved with Datastore2, so, I am not sure if I need to include something, I tried require(1936396537)

The script

The script is a local script inside of the mesh.

Mesh

The mesh is an anchored mesh with CanCollide on. The transparency is set to 1.

Code

Now, I am a noob when it comes to anything leaderstat, but I've always had this problem with leaderstats.

local DataStore2 = require(1936396537)

local player = game.Players.LocalPlayer
local stats = player:FindFirstChild("leaderstats")
local points = stats:FindFirstChild("Points")

if points.Value <0 then
	script.Parent.Transparency = 0
else
	script.Parent.Transparency = 1
end

What I want to accomplish I want the script to make the mesh visible if the player's Points are bigger than zero.

Ending

Thank you! If you can help me, I'd really appreciate it! It would benefit a lot of my games!

1 answer

LocalScripts run only in select places as listed in its API reference:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

· A Player’s Backpack, such as a child of a Tool

· A Player’s character model

· A Player’s PlayerGui

· A Player’s PlayerScripts.

· The ReplicatedFirst service

This means your LocalScript will not execute as it under a mesh that presumably isn't a descendant of the above objects.


P.S. You should not require the DataStore2 module if you won't be using it.

2 comments

0

Hello! Thank you for replying! That's neat about the LocalScripts, I thought they just showed for the one player. But will the mesh show to everyone else? Because I don't want it to... Also, this doesn't work, unfortunately. I put it in a normal script.

0

In a normal script you can't use game.Players.LocalPlayer since it's not associated to a single client. Instead you should use a LocalScript but place it in an object where it can execute, e.g. StarterPlayerScripts, where you can run the logic and change the mesh's transparency on just that client

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