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)
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