Hello!
So, I’m making a game, like a maze game where there are some guards and you need to stay out of their vision. When they walk, they create parts. Their name are “Waypoints”, and I made a special model for them. By the way, they are invisible (transparency 1). I want to make a gamepass that shows them (transparency 0). I made a script with :GetChildren() but it didn’t work. The script needs to find all the parts, and make them visible for those who have the gamepass. Note: The parts are being created every second so they aren’t pre-made by me. I tried to make it work like 2-3 times but I’ve failed. Here’s the code:
local WORKSPACE_PARTS = workspace:WaitForChild("WaypointsModel"):GetChildren()
local id = 6642754
game.Players.PlayerAdded:Connect(function(player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, id) then
for i, waypoint in ipairs(WORKSPACE_PARTS) do
waypoint.Transparency = 0
end
end
end)
The funky thing is that if you want the waypoints to be visible for only players with the game pass, you’ll have to make sure that the code is ran through client(LocalScript).
In other words, if the code is server-sided, all players will see the same replication(if a player with the game pass joins, the points become visible for all players). Otherwise, if the code is client-sided but it’s not working, it’s probably incorrectly parented.
If the player is added before the waypoints exist, then nothing will be updated. Put this code in a local script.
Try the following code:
local player = game.Players.LocalPlayer
local WORKSPACE_PARTS = workspace:WaitForChild("WaypointsModel")
local id = 6642754
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
while true do
for i, waypoint in ipairs(WORKSPACE_PARTS:GetChildren()) do
waypoint.Transparency = 0
end
wait(1)
end
end
Please do not just say “Not Working”. Are there any errors, are parts existing? This code worked perfectly for me with a demo gamepads, you are doing something wrong.
It only runs every second. Also, setting values to the current values has no effect. While it may be slightly better practice, I prefer to do it this way. Both ways would work.
Glad that it works now but I’m a little confused as to why you need to loop through it every second, and also for this you don’t need to use ipairs.
local player = game.Players.LocalPlayer
local WORKSPACE_PARTS = workspace:WaitForChild("WaypointsModel")
local id = 6642754
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
for _, waypoint in pairs(WORKSPACE_PARTS:GetChildren()) do
waypoint.Transparency = 0
end
end