Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I Need Help With The Current Script I Have Not Working, Could You Please Help Me?

Asked by 5 years ago

I have a script here, that when the part is transparent == 0, the player is supposed to get +$50 every 5. I'm not sure how to fix the problem, please help!

while true do
    player = game.Players:GetPlayerFromCharacter
    if script.Parent.Transparency == 0 then
        local stats = player:findFirstChild("leaderstats")
        local add = 50
        local cash = stats:findFirstChild("Cash")
        cash.Value = cash.Value + add
        wait(5)
    end
end
0
Isn't 1 the transparency for a part? rochel89 42 — 5y
0
?? Darkcraft10 20 — 5y
0
Do you want them to gain cash when the part is visible or invisible? If visible. .Transparency == 0, if invisible, .Transparency == 1. You may also consider adding a wait() statement outside of your conditional statement. SummerEquinox 643 — 5y

1 answer

Log in to vote
0
Answered by
LuaDLL 253 Moderation Voter
5 years ago
Edited 5 years ago

You were doing GetPlayerFromCharacter but you didnt define from what character

If you are trying to do it from a part being touched do this

local CanGet = true -- If They Can Get Cash From Touch

script.Parent.Touched:Connect(function(hit)
    local HitParent = hit.Parent -- The Parent Of hit
    if HitParent:FindFirstChild("Humanoid") then -- Checks If The Parent Of The Part That Touched The Part Has A Humanoid.
        local Player = game.Players:GetPlayerFromCharacter(HitParent) -- Gets The Player From The Players Character
            if script.Parent.Transparency == 0 and CanGet then -- If The Part Is Visible
                local stats = player:FindFirstChild("leaderstats")
                local add = 50 -- Amount To Add
                local cash = stats:FindFirstChild("Cash")
                cash.Value = cash.Value + add -- Adds 50("add") to current Cash Amount
            script.Parent.Transparency = 1 -- Sets part to invisible
            CanGet = false -- Sets "CanGet" to false
            wait(5) -- waits 5 seconds
            script.Parent.Transparency = 0 -- Sets part to visible
            CanGet = true -- Sets "CanGet" to true
            end
    end
end)
0
Thank you! Darkcraft10 20 — 5y
0
Your welcome! Good luck with your game. LuaDLL 253 — 5y
Ad

Answer this question