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

Value is not a valid member?

Alright this is really giving me a brick wall. Line 30, it's giving me a "Value is not a valid member" error. It's also pointing to the click(Mouse) for some reason. I click - it print prints tower 1 - I click again, it prints tower 2 (BUT does not actually update the CFrame value..) I click again, and it throws this error. I don't know why the second value is refusing to even update. Tower1 and Tower2 are both cframe values. Script is in a gui. (localscript)

I don't know how this manages to print "Tower 2 selected" once without actually updating the value, then breaking. I put the "Local Tower1/2 =" parts IN the function, and that removes the error but for some godforsaken reason, onlyTower1 value updates. What on earth?

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
local RayIgnore = {workspace.RayIgnore, workspace.BasePlate}

local Ready = true

local Tower1 = script.Parent.Tower1
local Tower2 = script.Parent.Tower2

function click()
	local WallType = script.Parent.WallType
	local CanBuild = script.Parent.CanBuild
	local CanPlace = script.Parent.CanPlace


	Mouse.TargetFilter = workspace.Template
	

		
		


	if CanBuild.Value == true and Ready == true then
		
		if Mouse.Target.Parent.Name == "Tower" and Tower1.Value.p == Vector3.new(0,0,0) then
			Tower1.Value = Mouse.Target.Parent.OriginPart.CFrame
			print("Tower 1 selected")
			print(Tower1)
		else if Mouse.Target.Parent.Name == "Tower" and Tower1.Value.p ~= Vector3.new(0,0,0) and Tower2.Value.p == Vector3.new(0,0,0) and Tower1.Value.p ~= Mouse.Target.Parent.OriginPart.CFrame.p then 
			Tower2 = Mouse.Target.Parent.OriginPart.CFrame
			print("Tower 2 selected")
			CanPlace.Value = true
		else if Mouse.Target.Parent.Name ~= "Tower"  then
			print("Towers cleared")

			
		end	
		end
		end
		
	end
end



    Mouse.Button1Down:connect(function()
    click(Mouse)
    end)


3 comments

0

error is here "Tower1.Value.p "

0

What is the value?

0

The default CFrame value, 0,0,0? I don't understand why this matters

1 answer

✓ Accepted answer

Try this :

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
local RayIgnore = {
	workspace.RayIgnore,
	workspace.BasePlate
}

local Ready = true

local Tower1 = script.Parent.Tower1
local Tower2 = script.Parent.Tower2

function click()
	local WallType = script.Parent.WallType
	local CanBuild = script.Parent.CanBuild
	local CanPlace = script.Parent.CanPlace
	
	Mouse.TargetFilter = workspace.Template
	
	if CanBuild.Value == true and Ready == true then

		if Mouse.Target.Parent.Name == "Tower" and Tower1.Value.p == Vector3.new(0, 0, 0) then
			Tower1.Value = Mouse.Target.Parent.OriginPart.CFrame
			print("Tower 1 selected")
			print(Tower1)
		elseif Mouse.Target.Parent.Name == "Tower" and Tower1.Value.p ~= Vector3.new(0, 0, 0) and Tower2.Value.p == Vector3.new(0, 0, 0) and Tower1.Value.p ~= Mouse.Target.Parent.OriginPart.CFrame.p then 
				Tower2.Value = Mouse.Target.Parent.OriginPart.CFrame
				print("Tower 2 selected")
				CanPlace.Value = true
		elseif Mouse.Target.Parent.Name ~= "Tower" then
			print("Towers cleared")
			
		end
	end
end

Mouse.Button1Down:connect(click)

I tried to optimize it and beautify it. Your error seems to be at line 31 (your code) :

 Tower2 = Mouse.Target.Parent.OriginPart.CFrame

Tower2 isn't anymore a CFrameValue but a variable holding a CFrame value

2 comments

0

Thank you! I won't use the beautification, for personal reasons, but I completely missed the Tower2 part you pointed out - the error directed me in the wrong direction. Thank you for the help.

0

Actually the error wasn't pointing me wrongly - This explains why the script only worked once. after it messed up the Tower2 part, it would no longer run without erroring.

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