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

Script not finding the right mesh in ReplicatedStorage. What am I doing wrong & how can it be fixed?

Asked by 6 years ago

Today, I started working on a basic "Pet Script" for a game that I'm developing. I want to give the player a mesh that is called what ever the value of game>Players>LocalPlayer>Pet>PetName>Value is. Not give the player a mesh that's called "petname" in ReplicatedStorage; how can this be fixed?

Code:

local plr = game.Players.LocalPlayer
local petname = game.Players.LocalPlayer.Pet.PetName.Value
local mesh = game.ReplicatedStorage.petname
local fly = game.Players.LocalPlayer.Pet.DoesItFly.Value

--[[ Line 3 should find the value of line 2 but instead it's looking in ReplicatedStorage
    for something called "petname". How can I fix this? 
    Basically, I want to give the player
    a mesh that has the name of what ever the 
    value of game>Players>LocalPlayer>Pet>PetName>Value is ]]

wait(2)
local part = Instance.new('Part', workspace[plr.Name].Torso)
part.CanCollide = false
part.Anchored = true
part.Size = Vector3.new(1,1,1)
mesh:Clone().Parent = part
local direction = CFrame.new(part.Position, plr.Character['Left Leg'].Position).lookVector
local increment = direction * 4
while true do
    wait()
    part.CFrame = game.Workspace[plr.Name]['Torso'].CFrame + (direction * increment) + Vector3.new(-5,0,0)
    part.Rotation = game.Workspace[plr.Name]['Torso'].Rotation + (direction * increment) + Vector3.new(-1,-2,increment)
end

1 answer

Log in to vote
0
Answered by 6 years ago

There's a simple fix for this. Use can use FindFirstChild to find the value of petname in the Replicated Storage.

local plr = game.Players.LocalPlayer
local petname = game.Players.LocalPlayer.Pet.PetName.Value
local mesh = game.ReplicatedStorage:FindFirstChild(petname)
local fly = game.Players.LocalPlayer.Pet.DoesItFly.Value

Let me know if you have any issues.

0
It worked. Thank you! Michael_TheCreator 166 — 6y
Ad

Answer this question