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.
#How do I weld stuff to the player model when they spawn?
1 messages · Page 1 of 1 (latest)
local Morph = Model:Clone()
also create a new WeldConstraint
just tested this it didnt change anything
does it have to be a weldconstraint specifically?
its better practice
its a weld
no but weldconstraint is probably your best way to go
hold on is it in r6
weldconstraint keeps positions relatice
this is the weld that is referenced
yes
this is a good point
part0 is the part following
you could try switch the roles
id recommend creating a new weldconstraint
weldconstraint > weld high diff
nothing changed
** You are now Level 5! **
o ok
do you mean create a new one via script
you also dont need to connect playeradded
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
ye
is this how im supposed to make it create one
try that
yes, dont forget to set its parent to humanoidrootpart and then set offset position
if i just want it to go to the player do i need to set the offset position somewhere
so its kinda bugged and undefined
no
i assumed since theres a humanoid inside of it they would connect
yes. the offset position is the one you set it to, once it is set then the part will always move relative to the weld0
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
so if i wanted the model's humanoid to be stuck to the torso then what would it be
would it just be 0,0,0
game:GetService("Players").PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
--Code here
end)```
it would be model:PivotTo(humanoidRootPart.CFame)
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
under WeldCon.Part1
do
Morph:PivotTo(character.HumanoidRootPart.CFrame)
been ages huh
any error?
the ones in analysis are disabled
theyre the old script
the waitforchild error is on the script were using
ok ok wait
i ser
** You are now Level 34! **
great, parent the weld to something too
you may need to parent the weld too
this does not work
ok were getting somewhere
it works on spawn
however
it does not work when i reset
how do i switch it to reset instead of spawn
usually you make a function and connect to when humanoid dues
then start the chain of events once more
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
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
how would i do that i dont have experience with tables
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 👍
this is a lot more confusing and i have no idea how id tie this into the script that i already have
rip
i tried just adding this to the end and it didnt work
could you explain how to make the table thing work
bro
thats definitely not logically correct
you can use playeradded:connect for your problem
if player.CharacterAdded then 🔥 🔥
--your model cloning logic here
end
game:GetService("Players").PlayerAdded:Once(function(player)
player.CharacterAdded:Connect(onCharacterLoad)
end)```
oh hello no
nvm wait should it be like htis
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
like this???
yes but remove the local character line
i mean were getting somewhere???
ts been going on for like 4 hours
alright
mf how long does it take you to make games
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
does this use like :Died() or something
local humanoid = character.Humanoid
humanoid.Died:Once(function()
end)
I like how its just you and him with no 1 else
hes my goat
how do i change this to save it into a table
well its magical
do i add something to the function part
i did that last time but i couldnt figure out where to put the other parts
aha
ts ok bro
change
local Morph = Model:Clone()
to
local Morph = modelTable[1] or Model:Clone()
then
character.Humanoid.Died:Once(function() table.insert(modelTable, Morph) end)
no, but you can save its reference in the workspace
which is the same for what you are trying to achieve
where in there would this go
inside of the function or at the bit at the end
** You are now Level 6! **
and the last piece is:
under
local Morph=
do
if modelTable[1] then table.remove(modelTable, 1) end
the ground thing is welded to my torso
i think we need to reset the position
somehow
it reattaches but the position is the same as when i died
wouldnt the old weld delete itself when the player respawns
or
wait
let me check if its still there
between the if and local weldcon do
local previousWeld = Morph.HumanoidRootPart:FindFirstChild("WeldConstraint")
if previousWeld then previousWeld:Destroy() end```
theres only one weld constraint
as i expected it didnt work
hm
i have a feeling this is a simple solution, is there no way to reset the offset to 0
this is what the weldconstraint looks like when i reset btw
should this go in here or something
`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)`
:c
doesnt work anyways
does the model have a primarypart?
idk what that did but it made it worse i keep spawning outside of the map now
the humanoid is the primary part
oh wait maybe its a logical error
also i reverted this so i stop going outside of the map
you set weld then reposition poarts
no that was good
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
when pivotto is infront of parent this happens
thats supposed to happen
thats because logical order was incorrect
try the version i sent
this works
perfectly
YES
were so back
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
its literally just what you did
heres a video of it working
beuaitulf
wait
?!?!?!
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
how would i do that
in onCharacterLoad()
at the top do
local correctTeam = "team here"
local team = (player.Team == correctTeam)
if not team then return end```
is that all
i wonder if thatll work
it did not print anything
ok so it prints the team that im on now
but the board doesnt show
even if im on the right one
oops my bad i said playerbycharacter im just not paying this thread much attention 💀
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
** You are now Level 11! **
it prints the name of the team
@elfin hawk @elfin hawk @elfin hawk @elfin hawk
but how
team is in lowercase
it would show an error
try this
if not player.Team == “Player” then return end
can u send screenshot of script again lela
please
when i used ur code it had these errors
just do if player.Team ~= currentTeam then return end
i still havent figured this out
how do i reference the player's team if i cant reference the player
Did this take you 5 hours 😭
or that
oh mbmb
put the 1 not in quotation marks as
player not Player
both didnt work i tried
im just gonna leave it as it is for now
maybe ill revisit it later