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

What is wrong with this script? [Edited]

I looked through everything. What's wrong with it?

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

Thanks in advance for your help!

==EDIT== Okay, so when I checked the Output it said that the error was somewhere in line 2:

    if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent.Money.Value >= 200 and hit.Parent.Name == script.Parent.Parent.Parent.Owner.Value then

1 answer

Well you checked for the player then decided to access the character to change the money silly(:

Also, you can use a for loop to manipulate the walls for efficiency.

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

script.Parent.Touched:connect(function(hit)
	if db == false then
		db = true
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr and plr.Money.Value >= 200 and plr.Name == owner.Value then
        	-----------------------------
			plr.Money.Value = hit.Parent.Money.Value - 200
        	-----------------------------      
			local walls = script.Parent.Parent.Parent.WallUpgrade2
		-----------------------------
			for i = 1,4 do
				local wall = walls:FindFirstChild("Wall"..tostring(i))
				wall.Transparency = 0
				wall.CanCollide = false --You might want this to be true:P
			end
        	-----------------------------
			local TextLabel = script.Parent.Parent.BuyWallsLabel.SurfaceGui.TextLabel
			script.Parent.Transparency = 1
			script.Parent.CanCollide = false
			TextLabel.TextTransparency = 1
			script.Disabled = true
        	-----------------------------
		end
		db = false
	end
end)

8 comments

0

There was an error in line 5. Mind reviewing it. I did and I found nothing.

0

Could you give me the error please?

0

It just said that it was disconnected because of an exception

0

Oh, sorry I didn't put a debounce. And did you make sure you had enough money?

0

Error on line 7

0

Uhhh.. no?

0

This is what came up in output: 00:43:52.584 - Money is not a valid member of Player 00:43:52.584 - Script 'Workspace.BuyWalls2.BuyWalls.Script', Line 8 00:43:52.585 - Stack End 00:43:52.585 - Disconnected event because of exception

0

Okay well then you got somethin wrong n0t me.

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