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

My script is not working, why?

This script was brought up in another question, but it was a while a go and was not given a working answer. Please go over my script and help me figure out what is wrong with it.

local owner = script.Parent.Parent.Parent.Owner
local db = false

script.Parent.Touched:connect(function(hit)
    if db == false then
        db = true
        if hit.Parent.leaderstats.Money.Value >= 200 and hit.Parent.Name == owner.Value then
            -----------------------------
            hit.Parent.leaderstats.Money.Value = hit.Parent.leaderstats.Money.Value - 200
            -----------------------------      
			script.Parent.Parent.Parent.WallUpgrade2.Wall1.Transparency = 0
			script.Parent.Parent.Parent.WallUpgrade2.Wall1.CanCollide = true
			script.Parent.Parent.Parent.WallUpgrade2.Wall2.Transparency = 0
			script.Parent.Parent.Parent.WallUpgrade2.Wall2.CanCollide = true
			script.Parent.Parent.Parent.WallUpgrade2.Wall3.Transparency = 0
			script.Parent.Parent.Parent.WallUpgrade2.Wall3.CanCollide = true
			script.Parent.Parent.Parent.WallUpgrade2.Wall4.Transparency = 0
			script.Parent.Parent.Parent.WallUpgrade2.Wall4.CanCollide = true
            -----------------------------
            script.Parent.Transparency = 1
            script.Parent.CanCollide = false
            script.Parent.Parent.BuyWallsLabel.SurfaceGui.TextLabel.TextTransparency = 1
            script.Disabled = true
            -----------------------------
        end
        db = false
    end
end)

Thank you in advance for your help.

BTW: There is an error in line 7. ;)

4 comments

0

Well, first of all, if it's a leaderboard you're trying to access, it's not going to be in hit.Parent. It'll be in the player, not the player's character.

0

How do I find the player, not the char?

0

I already answered this. And fixed all the errors.

0

It didn't work.

1 answer

You will have to find the player's character:

(put this inside the Touched function)

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- This method searches Players for a player that has the character model we input.

if player then -- Make sure it exists before we continue. If it doesn't exist, it could break the game.
	local stat = player:findFirstChild("leaderstats"):findFirstChild("Money")

	if stat then
		-- code.
	end
end

2 comments

0

What code do I put where you say 'code.'?

0

Whatever you want it to do. "stat" can be used as a shortcut to changing the value. (stat.Value = 2 for example)

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