Weld breaks in-game, but not in play-solo?

Play solo version:

In-game version:

I’ve tested the weld multiple times and it works perfectly fine in play solo, only when in-game does it break. I don’t know what the issue is, the code works perfectly fine in studio.

Here is my set up / code:

Summary

a

Any help is appreciated.

1 Like

Try putting print lines in each section to see what the output is by pressing shift F9 in game.
It might help to see exactly where the script is failing.

Also I seem to remember issues with the way Roblox accesses a player in-studio and in-game with scripts. I don’t recall what the exact issue is, someone else can probably point it out exactly.

3 Likes

It appears that what’s going on here is, you’re creating the weld locally (on the client). I’d be almost certain you have FilteringEnabled on. In which case, the weld would work in Play solo as currently the server and client are the same thing. Online however, the server ignores changes created by the client, and therefore never knows that the weld even exists. The absolute simplest test is to turn off FilteringEnabled just long enough to test it. If it works normally with FilteringEnabled off then you know that’s the cause.

3 Likes

Use Accessories instead of a part.

You can also read more about FE

2 Likes

@Scottifly

RobloxScreenShot20180716_024200605

It says head is not valid member of model.
Here’s how I’m accessing the player’s head: local player = game.Players.LocalPlayer.Character.Head
Am I doing something wrong?

1 Like

Turned off filtering enable, it’s still not working. ;u;

Thank you Rui, I will look into this.

1 Like

Have you looked at the client logs in the console for errors? (F9 in published game). With FilteringEnabled on, you can weld things to your character from a LocalScript, the difference is that only you will see it. Because not even you are seeing the item appear on your character this suggests something else is wrong. One possibility is this line:

local face = game.ReplicatedStorage.BearFace:Clone()

This can fail in a published game if the line of code is encountered before BearFace has actually replicated to your client. In this case, you should have a red warning in your client logs. You need to wait for BearFace to replicate before trying to clone it. This can be as simple as

local face = game:GetService("ReplicatedStorage"):WaitForChild("BearFace"):Clone()

But… if you want everyone to see your character wearing the face, this point is moot, you need to clone the part and weld it from a server Script. This means sending a RemoteEvent from your client to the server to request the face be attached to your character.

But there are other options if you need to avoid a blocking call.

3 Likes

Unfortunately, I tried this and it still gave me the same result.
It is a 1 player game, so I would not have to worry about everyone seeing the face.

Here is what shows up in client log:

Here’s my my line 2 code:
local player = game.Players.LocalPlayer.Character.Head

Change

local player = game.Players.LocalPlayer.Character.Head

to

local player = game.Players.LocalPlayer

since that is actually the player. Then define the head as a local variable within the MouseButton1Click function using:

local head = player.Character:WaitForChild("Head")

To explain what is happening: You define the Player’s head before the character might even be fully loaded. In Play Solo this is not much of an issue because you run the code on your PC, but load times and order can be different on Roblox servers and therefore certain elements might not exist yet when your code tries to index them. This is what people usually refer to as a race condition.

Also, if you have your PlayerGui set to not reload upon death, you run into further issues because your character is remade but the LocalScript is not, so the LocalScript will still try to refer to the old head that is no longer accessible. The changes I suggested will make your code a little cleaner and should also fix this issue since now the head is redefined whenever you click the button.

1 Like

Thanks, everyone.
Untitled

3 Likes