Help With Scripting

I’m struggling to make a script for my game, its a bit like a tycoon but i need a script where when you step on a part if you have enough money then it will make a part visible, here is the script i have so far:

local player = game:GetService(“Players”).LocalPlayer
local part = workspace.BuyStages.ObbyPart1
local cash = player:WaitForChild(“leaderstats”):WaitForChild(“Cash”)
local Stage1 = game.Workspace[“Stage 1”]

while true do
part.Touched:Connect(function(hit)
if hit.Parent == player.Character then
if cash >= 100 then
Stage1.Visible = true
Stage1.CanColide = true
end
end
end)
end

can anyone help me?

1 Like

btw the indentations didnt show when i pasted the script, i have already added them in the real script though so dont worry about indentations and stuff

1 Like

Firstly just remove that while loop. Creating a connection will call that function when necessary.

Second. You should be doing Cash.Value in the if statement.

And finally you can format your code to be colored and more readable on the devforums by doing this

local var = test
if test then end

image

Those 3 characters at the start and end of the code block are backticks `

3 Likes
local player = game:GetService("Players").LocalPlayer
local part = workspace.BuyStages.ObbyPart1
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local Stage1 = game.Workspace:WaitForChild("Stage1")


part.Touched:Connect(function(hit)
  if hit.Parent == player.Character or player.CharacterAdded:wait() then
    if cash.Value >= 100 then
      Stage1.Transparency= 0
      Stage1.CanColide = true
    end
  end
end)

1 Like

Make sure to change your quotations from “ to "

1 Like

I thought .Visible only works for GUIs.

2 Likes

It indeed only works for UI’s and instances that have that property, and not for visual objects, I prob didnt notice that mistake.

1 Like

You forgot to change the transparency to a number after changing it from .Visible

1 Like

Maybe you should try this:


local player = game:GetService(“Players”).LocalPlayer
local part = workspace.BuyStages.ObbyPart1
local cash = player:WaitForChild(“leaderstats”):WaitForChild(“Cash”)
local Stage1 = game.Workspace[“Stage 1”]


part.Touched:Connect(function(hit)
  if hit.Parent == player.Character or player.CharacterAdded:wait() then
    if cash.Value >= 100 then
      Stage1.Transparency = 0
      Stage1.CanColide = true
    end
  end
end)

This wouldn’t work, check the quotation marks in the variables

1 Like

what script u using? localplayer (firstline) only works on a local script on the client
replace ur current code with this:

local part = workspace.BuyStages.ObbyPart1
local Stage1 = game.Workspace[“Stage 1”]

part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end
    local cash = player:WaitForChild(“leaderstats”):WaitForChild(“Cash”)
    if hit.Parent == player.Character then
        if cash.Value >= 100 then
            if Stage1:IsA("BasePart") then
                Stage1.Transparency = 0
                Stage1.CanColide = true
            else
                for _,p in ipairs(Stage1:GetDescendants()) do
                    if not p:IsA("BasePart") then continue end
                    p.Transparency = 0
                    p.CanColide = true
                    task.wait()
                end
            end
        end
    end
end)

It does work; all you have to do is anchor both parts.

ScreenGuis don’t have the Visible property, only Enabled.

1 Like

The .Visible property only works in text and image labels/buttons.

1 Like
local player = game:GetService(“Players”).LocalPlayer
local part = workspace.BuyStages.ObbyPart1
local cash = player:WaitForChild(“leaderstats”):WaitForChild(“Cash”)
local Stage1 = game.Workspace[“Stage 1”]

part.Touched:Connect(function(hit)
  if hit.Parent == player.Character then
     if cash >= 100 then
        Stage1.Visible = true
        Stage1.CanColide = true
     end
  end
end)

Try this, is it server sided also? If it is not try using physics service for the cancollide and visible stuff. The client should not change workspace properties because roblox thinks that’s hacking, switch it to a server script and when it’s clicked set the physic owner idk what it’s called to the player and fire a remote event to request the client to then cancollide it