Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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.

0
You would need to change the name of your string value. BulletproofVast 1033 — 3y
Ad
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

Answer this question