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

How do I make a script recognize the location of an objectvalue without being disabled?

Okay, so basically this is a code that goes into a textbutton into a introductory startergui in the new game Im developing. It is meant to remove the tools provided by similar buttons under the same parent frame in the case that they were to try to pick multiple "classes", and gain tools from each. Each button has a script that places and objectvalue named "Warrior". "Ranger", or "Mage" directly into the player. The problem is that the if/then statements will either stop working because they don't see the object, or in this case, it will do nothing, with no output. The following script does not work, and has no output in the debugger, which is in the "Warrior" button.

local Robloxian = script.Parent.Parent.Parent.Parent.Parent

local Mage = game.Lighting.Mage local Ranger = game.Lighting.Ranger local Warrior = game.Lighting.Warrior

function onClicked()

if Mage:IsAncestorOf(Robloxian) == true then Robloxian.Backpack:ClearAllChildren() Robloxian.StarterGear:ClearAllChildren() Robloxian.Mage:Remove()

elseif Ranger:IsAncestorOf(Robloxian) == true then 
	Robloxian.Backpack:ClearAllChildren()
	Robloxian.StarterGear:ClearAllChildren()
	Robloxian.Ranger:Remove()



	
	else print "Class selected!"
	
end

end

script.Parent.MouseButton1Click:connect(onClicked)

This other script is more simple, but it doesn't work at all if the player does not have the "Mage" value.

local Robloxian = script.Parent.Parent.Parent.Parent.Parent

function onClicked()

if Robloxian.Mage then Robloxian.Backpack:ClearAllChildren() Robloxian.StarterGear:ClearAllChildren() Robloxian.Mage:Remove()

elseif Robloxian.Warrior then 
	Robloxian.Backpack:ClearAllChildren()
	Robloxian.StarterGear:ClearAllChildren()
	Robloxian.Warrior:Remove()

elseif Robloxian.Ranger then 
	Robloxian.Backpack:ClearAllChildren()
	Robloxian.StarterGear:ClearAllChildren()
	Robloxian.Ranger:Remove()

end

end

script.Parent.MouseButton1Click:connect(onClicked)

I'd appreciate it if somebody could just explain why the first one isn't working or yielding an output.

1 comment

0

Sorry about the sloppiness. It's my first time posting here.

1 answer

I formatted your code to make it easier to answer, don't accept this as a solution just yet.

local Robloxian = script.Parent.Parent.Parent.Parent.Parent

local Mage = game.Lighting.Mage 
local Ranger = game.Lighting.Ranger 
local Warrior = game.Lighting.Warrior

local function onClicked()
	if Mage:IsAncestorOf(Robloxian) then 
		Robloxian.Backpack:ClearAllChildren()
		Robloxian.StarterGear:ClearAllChildren() 
		Robloxian.Mage:Destroy()
	elseif 
		Ranger:IsAncestorOf(Robloxian) then 
		Robloxian.Backpack:ClearAllChildren()
		Robloxian.StarterGear:ClearAllChildren()
		Robloxian.Ranger:Destroy()
	else 
		print("Class selected!")
	end
end

script.Parent.MouseButton1Click:connect(onClicked)

This other script is more simple, but it doesn't work at all if the player does not have the "Mage" value.

local Robloxian = script.Parent.Parent.Parent.Parent.Parent

function onClicked()
	if Robloxian.Mage then 
		Robloxian.Backpack:ClearAllChildren() 
		Robloxian.StarterGear:ClearAllChildren() 
		Robloxian.Mage:Destroy()
	elseif Robloxian.Warrior then 
		Robloxian.Backpack:ClearAllChildren()
		Robloxian.StarterGear:ClearAllChildren()
		Robloxian.Warrior:Destroy()
	elseif Robloxian.Ranger then 
		Robloxian.Backpack:ClearAllChildren()
		Robloxian.StarterGear:ClearAllChildren()
		Robloxian.Ranger:Destroy()
	end
end

script.Parent.MouseButton1Click:connect(onClicked)

1 comment

0

Thanks, fam.

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