"attempt to call a Instance value" When trying to locate player's star on the map

Essentially I am trying to make an attack for my game where if you click once, it will spawn a star on the map whose name gets changed to “[Player]Star” once spawned
Clicking again I want it to teleport the player to the star and reload their stats that they had once they spawned the star, the star would then delete itself since the player already spawned themselves at that star waiting to be used again.

Here is the code I have for the tool that makes all that happen:

active = 1
ogName = script.Parent.Name
script.Parent.Activated:Connect(function()
	if active == 1 and script.Parent.Saved.Value == false and script.Parent.Parent.Humanoid.Health ~= math.huge then
		active = 0
		script.Parent.Saved.Value = true --Star has been spawned
		local g = game.ReplicatedStorage["Aftertale Sans"].SaveStar:Clone()
		g.owner.Value = script.Parent.Parent --Sets ObjectValue in star to Player's name
		g.MaxHP.Value = script.Parent.Parent.Humanoid.MaxHealth
		g.CurHP.Value = script.Parent.Parent.Humanoid.Health
		g.CurSPD.Value = script.Parent.Parent.Humanoid.WalkSpeed
		g.CurJMP.Value = script.Parent.Parent.Humanoid.JumpPower --These four lines save the Player's current stats
		g.Name = script.Parent.Parent.Name.."Star" --Names the star to [Playername]Star
		g.Parent = workspace
		g.PrimaryPart = g.Head
		g:SetPrimaryPartCFrame(script.Parent.Parent["Torso"].CFrame * CFrame.new(0,0,0))
		local cd = script.Parent.cd.Value
		local origcd = cd
		for i = 1,cd do
			script.Parent.Name = cd/(script.Parent.division.Value)
			task.wait(1/(script.Parent.division.Value))
			cd-=1
		end
		cd = origcd
		script.Parent.Name = "LOAD"
		active = 1
	elseif active == 1 and script.Parent.Saved.Value == true and script.Parent.Parent.Humanoid.Health ~= math.huge then
		active = 0
		script.Parent.Saved.Value = false
		local star = workspace(script.Parent.Parent.Name).."Star" --Problematic line
		star:Destroy()
		local cd2 = script.Parent.cd2.Value
		local origcd2 = cd2
		for i = 1,cd2 do
			script.Parent.Name = cd2/(script.Parent.division2.Value)
			task.wait(1/(script.Parent.division2.Value))
			cd2-=1
		end
		cd2 = origcd2
		script.Parent.Name = "LOAD"
		active = 1
	end
end)

But everytime I do the second part of the tool, it’ll just say “attempt to call a Instance value” in the Output at this line:

local star = workspace(script.Parent.Parent.Name).."Star"

I’ve already tried converting that line into like a function code, it seemed to not produce any errors in the prompt at first but when I tried making it actually do something it just provided the same error. I have also looked in Creator Hub for any help on the matter but none of them seemed to match the specific criteria of this issue

Clearly I am doing something wrong with trying to call the star by it’s new name by assigning the Player’s name with “Star” at the end of it, I did that to try and not confuse the game itself by calling the star by just the Player name but the Player also exists (The star itself is inside of a Model)
What should I do differently here? Any and all help will be greatly appreciated <3

UPDATE: I figured it out!

All I had to do was change the () to and it worked!

local guy = script.Parent.Parent.Name
		local star = workspace[guy.."Star"]

just for future reference, the reason your solution works is because Container[object] allows you to find dynamically set keys (things that get set after running the game).

the first approach of local star = workspace(script.Parent.Parent.Name).."Star" is incorrect because it is basically saying “call the function workspace() with argument script.Parent.Parent.Name, then add “Star” to the end of the result”. the error “attempt to call a Instance value” means that you tried to call a function on something that isn’t a function.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.