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

Can I get some help with this error that's causing my mind to fracture?

I keep getting an error on a line of code that should change a string value to the name of a part, and it makes no sense to me please help.

here's my script (Its only a small part of it to keep it simple, but i assure you everything else works):

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode[pickupkey] then
		if mouse.Target then
			if mouse.Target:FindFirstChild("Pickable") then
				local item = mouse.Target
				if item then
					local distanceFromItem = player:DistanceFromCharacter(item.Position)
					if distanceFromItem < 7 then
						-- we fill this in loadstring
						print("worked")
						game.ReplicatedStorage.Name.Value = item --HERES WERE THE ERROR POINTS OUT
						PickupItem:FireServer(item)
					end
				end
			end
		end
	end
end)

the error says: Players.Paczki_TCBC.PlayerScripts.LocalScript:35: attempt to index string with 'Value'

Please help dude, my head hurts.

3 answers

You cant name something 'Name' because 'Name' is a property of ReplicatedStorage. game.ReplicatedStorage.Name is 'ReplicatedStorage' so it doesn't go to the string value you want.

1 comment

0

You would need to change the name of your string value.

do this instead:

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode[pickupkey] then
		if mouse.Target then
			if mouse.Target:FindFirstChild("Pickable") then
				local item = mouse.Target
				local distanceFromItem = player:DistanceFromCharacter(item.Position)
				if distanceFromItem < 7 then
					print("worked")
					game.ReplicatedStorage:FindFirstChild("Name").Value = item.Name
					PickupItem:FireServer(item)
				end
			end
		end
	end
end)

basically I changed the errored line to item.Name instead of item

Your code:

UIS.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode[pickupkey] then
        if mouse.Target then
            if mouse.Target:FindFirstChild("Pickable") then
                local item = mouse.Target
                if item then
                    local distanceFromItem = player:DistanceFromCharacter(item.Position)
                    if distanceFromItem < 7 then
                        -- we fill this in loadstring
                        print("worked")
                        game.ReplicatedStorage.Name.Value = item --HERES WERE THE ERROR POINTS OUT
                        PickupItem:FireServer(item)
                    end
                end
            end
        end
    end
end)

Line 11:

game.ReplicatedStorage.Name.Value = item 

you have to change the value named "Name" because the Script thinks you renaming the ReplicatedStorage. Get it now? LOL gotta read your own code lol

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