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

Why does my script think a part doesn't exist?

Asked by 5 years ago

Hi.

I have a BoolValue that gets set to true when my game starts.

A global script in StarterCharacterScripts (ergo, in all the players) detect when this happens, finds the map that was automatically generated by another script and teleports the player to a part included named PlaceToStart. And before you ask, all of the maps that could be generated contains this part, at least that's what I found, and the part was anchored.

This is the code:

game.Workspace["Special Stuffs"].GameProgress.Changed:Connect(function() -- if the Game Progress has been updated
    if game.Workspace["Special Stuffs"].GameProgress.Value == true then -- if it is updated to say the game has started
        script.Parent.CFrame = game.Workspace.Map:FindFirstChildOfClass("Model").PlaceToStart.CFrame -- teleport to this part
    end
end)

but whenever I run it, I get one of these as an error (never all):

21:37:28.814 - Workspace.KicksForTricks56.GameTeleporter:3: attempt to index a nil value
21:42:38.957 - PlaceToStart is not a valid member of Model
21:45:48.891 - CFrame is not a valid member of Model

I tried using :FindFirstChild() and :WaitForChild(). It didn't give me an Infinite yield warning when I did it so I know it acknowledges that it exists, but it still doesn't think it's a vaild member of the map! I am baffled about why this is happening, especially when I check in Explorer and find it that the part still does exist, both in-game (after I get the error) and in editor mode. Does anybody know what is happening?

0
Is the part somehow local? OBenjOne 190 — 5y
0
I don't know what that means, but I think this may help: I don't spawn it via a local script but the maps are stored in server storage before being used, an Instance that may be local KicksForTricks56 36 — 5y
0
don't worry your part isn't local if the script that created it is in the workspace OBenjOne 190 — 5y
0
Wait... I don't even know if models have CFrames... hey, I don't think they do! Try setting a primary part for the model then instead of script.Parent.CFrame (on line 3) try script.Parent.PrimaryPart.CFrame OBenjOne 190 — 5y
View all comments (5 more)
0
Model probably don't have CFrames meaning that your part doesn't have anything to do with your error. The error is your explanation: CFrame is not a valid member of model. OBenjOne 190 — 5y
0
Thanks, that helped! :) KicksForTricks56 36 — 5y
0
You can set the cframe of a model with their primarypart. You can either assign the primarypart of the model manually or by a script. Let me make a example. SulaymanArafat 230 — 5y
0
Also it's a bad idea to put it in starterplayerscripts making so many can make unexpected behaviour with a single script in serverscriptservice doing the stuff and then teleporting all the players with a remote using :FireAllClients will do SulaymanArafat 230 — 5y
0
Although since I don't have enough information I'm not sure what to do, because some of your errors is because of either your hierarchy or that they dont exist. The most i can help is what i've said about the model cframes. :SetPrimaryPartCFrame would be the method to do so. https://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame SulaymanArafat 230 — 5y

1 answer

Log in to vote
0
Answered by
OBenjOne 190
5 years ago
Edited 5 years ago

Models Position can be changed with MoveTo. Not rly sure if this is the best way though.

http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo

MoveTo is like changing Position on a model

you can also use the primary part's CFrame.

PrimaryPart.CFrame is like useing CFrame on a model

0
How to make a link? OBenjOne 190 — 5y
Ad

Answer this question