#How do I weld stuff to the player model when they spawn?

1 messages · Page 1 of 1 (latest)

elfin hawk
#

I have this board that I want to attach to the player when they spawn. Im not very good at coding so i didn't expect to get this first try but it is starting to bug me. I have provided an image of the board and the current script. The board includes a model containing the parts and unions for the board and a HumanoidRootPart which I assumed I needed for it to work.

left ferry
#

local Morph = Model:Clone()

upbeat kiln
#

it still works the way he did it

#

he can acces the variable from anywhere now

left ferry
#

also create a new WeldConstraint

elfin hawk
elfin hawk
left ferry
#

its better practice

elfin hawk
#

its a weld

left ferry
#

no but weldconstraint is probably your best way to go

upbeat kiln
#

hold on is it in r6

left ferry
#

weldconstraint keeps positions relatice

elfin hawk
#

this is the weld that is referenced

elfin hawk
left ferry
upbeat kiln
#

you could try switch the roles

left ferry
upbeat kiln
#

weldconstraint > weld high diff

elfin hawk
lunar yarrowBOT
#

studio** You are now Level 5! **studio

upbeat kiln
elfin hawk
left ferry
#

yes

#

local newWeldConstraint = Instance.new("WeldConstraint")

upbeat kiln
#

are there any errors in the output

#

that u can see

left ferry
#

you also dont need to connect playeradded

upbeat kiln
#

I think he needs player variabke

#

unless its a local script

left ferry
#

you can use

local character = player.Character or player.CharacterAdded:Wait()

essentially does the same but its aesthetically better and prevents that nasty unnecessary loop/connect
keeps everything in series

upbeat kiln
#

ye

elfin hawk
#

is this how im supposed to make it create one

upbeat kiln
#

try that

left ferry
#

yes, dont forget to set its parent to humanoidrootpart and then set offset position

upbeat kiln
#

wait

#

yes I was aboutta say tagt

#

its parent is still nil

elfin hawk
upbeat kiln
#

so its kinda bugged and undefined

elfin hawk
#

i assumed since theres a humanoid inside of it they would connect

upbeat kiln
#

set it to 0, 0, 0

#

if its directly inside

left ferry
#

thats where weldconstraint is applicable, it keeps two parts offset indefinitely until you change a position. try set the model cframe to the humanoidrootpart cframe and it will always remain there relatice to the humanoidrootpart

elfin hawk
#

would it just be 0,0,0

left ferry
#

game:GetService("Players").PlayerAdded:Connect(function(player)

local character = player.Character or player.CharacterAdded:Wait()

--Code here

end)```
left ferry
#

for a model

and model.CFrame = HumanoidRootPart.CFrame + OFFSET

#

remember, the other parts position is not an offset, its a world position. it only remains relative to the other part when in motion

left ferry
#

sorry i missed the "

#

Players: should be Players"

left ferry
# elfin hawk

under WeldCon.Part1
do
Morph:PivotTo(character.HumanoidRootPart.CFrame)

elfin hawk
#

still isnt working yet

left ferry
#

finally

#

do Morph.Parent = workspace

#

c:

elfin hawk
#

does not work

upbeat kiln
#

been ages huh

left ferry
#

any error?

elfin hawk
#

the ones in analysis are disabled

#

theyre the old script

#

the waitforchild error is on the script were using

#

ok ok wait

left ferry
lunar yarrowBOT
#

studio** You are now Level 34! **studio

elfin hawk
#

i switched the . to a :

#

and something changed

left ferry
#

great, parent the weld to something too

elfin hawk
#

it spawns but it isnt welded

left ferry
#

you may need to parent the weld too

elfin hawk
#

this does not work

left ferry
#

parent should be Parent

#

remember: code is case sensitive

elfin hawk
#

ok were getting somewhere

#

it works on spawn

#

however

#

it does not work when i reset

left ferry
#

yeah

#

because you need to perform the action on reset

elfin hawk
#

how do i switch it to reset instead of spawn

left ferry
#

usually you make a function and connect to when humanoid dues

#

then start the chain of events once more

elfin hawk
#

can i make the clone reattach to the new player once they die so that A. anything on it is saved and B. so the clones dont begin to stack up and lag the server

left ferry
#

because you are only connecting it to when a player is added it will only work when someone joins

#

yes

#

store it in a table

elfin hawk
#

how would i do that i dont have experience with tables

left ferry
#

when player dies store the clone to a table of free models

check if table length of contents > 1 then fetch from the table

#

local freeModels = {}

player dies here

add to table:
table.insert(freeModels, playersWeldedModel)

when player joins
if not #freeModels >= 1 then clone else clone = freeModels[1] end

#

its fairly simple 👍

elfin hawk
left ferry
#

rip

elfin hawk
#

i tried just adding this to the end and it didnt work

#

could you explain how to make the table thing work

left ferry
#

bro

#

thats definitely not logically correct

#

you can use playeradded:connect for your problem

upbeat kiln
#

if player.CharacterAdded then 🔥 🔥

left ferry
#

--your model cloning logic here

end

game:GetService("Players").PlayerAdded:Once(function(player) 
player.CharacterAdded:Connect(onCharacterLoad)
end)```
left ferry
#

oh hello no

elfin hawk
#

nvm wait should it be like htis

left ferry
#

why the first loop in playeradded

#

bro just copy and paste what i sent

#

bro is cooking something diabolical

#

im saving that for when u stick around and i need to remind u of how far u have come

elfin hawk
#

is this it

#

or do i need to add the model variable inside too

left ferry
#

bro just copy paste what i sent

#

u got the spirit

elfin hawk
#

what are you

#

asking me

#

to do

#

ive tried to much stuff already

left ferry
#

yes

#

now put the model clone logic in the function

#

without the player.added

elfin hawk
#

like this???

left ferry
#

yes but remove the local character line

elfin hawk
left ferry
#

beautiful

#

stunning

#

its a true masterpiece

elfin hawk
#

i mean were getting somewhere???

upbeat kiln
#

ts been going on for like 4 hours

left ferry
#

alright

elfin hawk
left ferry
#

so now you need to pool the objects

when humanoid dies the player is respawned so when the humanoid dies you save the object reference to a table for later reuse

elfin hawk
left ferry
#

local humanoid = character.Humanoid

humanoid.Died:Once(function()

end)

upbeat kiln
elfin hawk
elfin hawk
left ferry
#

well its magical

elfin hawk
#

do i add something to the function part

left ferry
#

yes

#

first you declare a table

local modelTable = {} --at the top```
elfin hawk
#

i did that last time but i couldnt figure out where to put the other parts

left ferry
#

aha

#

ts ok bro

#

change

local Morph = Model:Clone()

to

local Morph = modelTable[1] or Model:Clone()
elfin hawk
#

ok i get this

#

can you save an object in a table though

left ferry
#

then

character.Humanoid.Died:Once(function() table.insert(modelTable, Morph) end)
left ferry
#

which is the same for what you are trying to achieve

elfin hawk
#

inside of the function or at the bit at the end

left ferry
#

at the bottom of onCharacterLoad

#

inside the function though

elfin hawk
lunar yarrowBOT
#

studio** You are now Level 6! **studio

left ferry
#

and the last piece is:

under

local Morph=

do

if modelTable[1] then table.remove(modelTable, 1) end

elfin hawk
left ferry
#

beautiful

#

try it out

#

do
it
be
bussin?

elfin hawk
#

the ground thing is welded to my torso

#

i think we need to reset the position

#

somehow

left ferry
#

wdym the ground is welded to ur torso

#

does it work everytime u die atleast?

elfin hawk
elfin hawk
left ferry
#

ah

#

yes

#

maybe bc

#

you dont delete the old weld and add a new one

elfin hawk
#

wouldnt the old weld delete itself when the player respawns

#

or

#

wait

#

let me check if its still there

left ferry
#

between the if and local weldcon do

local previousWeld = Morph.HumanoidRootPart:FindFirstChild("WeldConstraint")

if previousWeld then previousWeld:Destroy() end```
elfin hawk
#

theres only one weld constraint

left ferry
#

oh

#

well

#

do it anyways for continuity

elfin hawk
#

as i expected it didnt work

left ferry
#

hmhm

#

well

#

i mean its working right?

elfin hawk
#

it still works

#

but like

#

its also still welding to the wrong position

left ferry
#

move pivotto to below the parent to workspace

#

thats the only thing i can think of

elfin hawk
#

didnt work

left ferry
#

hm

elfin hawk
#

i have a feeling this is a simple solution, is there no way to reset the offset to 0

left ferry
#

yes just PivotTo(CFrame.new(vector.zero))

#

to set to 0,0,0

elfin hawk
#

this is what the weldconstraint looks like when i reset btw

elfin hawk
left ferry
#

no

#

it goes in the onCharacterLoad function

#

show me your current code

elfin hawk
#

`local Model = workspace:WaitForChild("StarterCharacter")
local SavedModel = {}

function onCharacterLoad(character)

local Morph = SavedModel[1] or Model:Clone()
if SavedModel[1] then table.remove(SavedModel, 1) end
local previousWeld = Morph.HumanoidRootPart:FindFirstChild("WeldConstraint")
if previousWeld then previousWeld:Destroy() end
local WeldCon = Instance.new('WeldConstraint')
WeldCon.Part0 = Morph.HumanoidRootPart
WeldCon.Part1 = character:WaitForChild("Torso")
WeldCon.Parent = Morph.HumanoidRootPart
Morph:PivotTo(character.HumanoidRootPart.CFrame)
Morph.Parent = workspace
character.Humanoid.Died:Once(function() table.insert(SavedModel, Morph) end)

end

game:GetService("Players").PlayerAdded:Once(function(player)
player.CharacterAdded:Connect(onCharacterLoad)
end)`

left ferry
#

as in below

#

not above

elfin hawk
#

i thought i already did that 😞

#

it mustve reset idk

left ferry
#

:c

elfin hawk
#

doesnt work anyways

left ferry
#

does the model have a primarypart?

elfin hawk
#

idk what that did but it made it worse i keep spawning outside of the map now

elfin hawk
left ferry
#

oh wait maybe its a logical error

elfin hawk
left ferry
#

you set weld then reposition poarts

left ferry
#

that was correct

#

dont undo that

#

`local Model = workspace:WaitForChild("StarterCharacter")
local SavedModel = {}

function onCharacterLoad(character)

local Morph = SavedModel[1] or Model:Clone()
if SavedModel[1] then table.remove(SavedModel, 1) end
local previousWeld = Morph.HumanoidRootPart:FindFirstChild("WeldConstraint")
if previousWeld then previousWeld:Destroy() end
local WeldCon = Instance.new('WeldConstraint')
Morph.Parent = workspace Morph:PivotTo(character.HumanoidRootPart.CFrame)

WeldCon.Part0 = Morph.HumanoidRootPart
WeldCon.Part1 = character:WaitForChild("Torso")
WeldCon.Parent = Morph.HumanoidRootPart

character.Humanoid.Died:Once(function() table.insert(SavedModel, Morph) end)

end

game:GetService("Players").PlayerAdded:Once(function(player)
player.CharacterAdded:Connect(onCharacterLoad)
end)`

#

try this

#

i made it weld only after setting position

#

not before, which would cause ur glitch

elfin hawk
left ferry
#

thats supposed to happen

#

thats because logical order was incorrect

#

try the version i sent

left ferry
#

YES

elfin hawk
#

were so back

left ferry
#

because we were setting the weld and then changing the position (meaning the weld was never set local to the characters position, it moved the character after the weld like a model and recentred the morph+character as a whole model - stupid me)

now we set the morphs position to the characters AND THEN WELD

#

show me teh final code bro

elfin hawk
#

its literally just what you did

left ferry
#

ye but i wanna show it in studio 💀

#

to display ur awesome skill 💀

elfin hawk
elfin hawk
left ferry
#

beuaitulf

elfin hawk
#

wait

left ferry
#

?!?!?!

elfin hawk
#

give me a second

#

can we make it

#

only work if ur in a specific team

#

wouldnt it just be like an if statement or something

left ferry
#

yeah

#

its just getplayerfromcharacter

elfin hawk
#

how would i do that

left ferry
#

in onCharacterLoad()

at the top do


local correctTeam = "team here"

local team = (player.Team == correctTeam)

if not team then return end```
elfin hawk
#

is that all

left ferry
#

i wonder if thatll work

elfin hawk
#

its back to not working at all

left ferry
#

try print(team) above if not team

#

see what your team is

elfin hawk
#

it did not print anything

left ferry
#

show code

#

oh sorry i mean print(player.Team)

elfin hawk
#

that did not change anything

upbeat kiln
#

bro its getplayerfromcharacter

#

thats why there is an error

#

Id

elfin hawk
#

OH

#

that makes

#

a lot more sense

upbeat kiln
#

yr

#

ye

#

trey it now

elfin hawk
#

ok so it prints the team that im on now

#

but the board doesnt show

#

even if im on the right one

upbeat kiln
#

Im sorry I wasnt here since the start

#

uhh what baord

#

what tea,

left ferry
#

oops my bad i said playerbycharacter im just not paying this thread much attention 💀

upbeat kiln
#

hold on

#

when you print team does it show a boolvalue

#

since team is the varuabke for a boolvalue

#

I feel like ur overcomplicating it

lunar yarrowBOT
#

studio** You are now Level 11! **studio

upbeat kiln
#

just do

#

if not player.Team == “Player” then return end

elfin hawk
upbeat kiln
#

@elfin hawk @elfin hawk @elfin hawk @elfin hawk

upbeat kiln
#

team is in lowercase

#

it would show an error

elfin hawk
upbeat kiln
#

try this

#

if not player.Team == “Player” then return end

#

can u send screenshot of script again lela

#

please

elfin hawk
left ferry
elfin hawk
#

it doesnt know what player is

#

it still says player is an unknown global

elfin hawk
#

i still havent figured this out

#

how do i reference the player's team if i cant reference the player

elfin hawk
#

is this the time where everyone gives up

#

i still need the team script

worn jackal
#

Did this take you 5 hours 😭

upbeat kiln
#

put the 1 not in quotation marks as

#

player not Player

elfin hawk
#

im just gonna leave it as it is for now

#

maybe ill revisit it later