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