Whatsup developers,
personally it’s been a while since I’ve scripted and I stumbled against a problem here:
At my task.defer function (function is at the bottom) it keeps printing nil, while the Attachment1’s value is not nil. Could anyone explain why it still prints nil? Did I do something wrong with the playerAttach variable? Attachment1 should be the player by the way.
Please ask for more background information if you need that to help me.
Thanks for helping in advance.
local touchpart = script.Parent
local beam = touchpart.Beam
local highLight = touchpart.Highlight
touchpart.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
beam.Attachment1 = hit.Parent.HumanoidRootPart.RootAttachment
highLight.Enabled = true
end
end)
task.defer(function()
while task.wait(0.5) do
if beam.Attachment1 ~= nil then
local playerAttach = game.Players:GetPlayerFromCharacter(beam.Attachment1)
print(playerAttach)
end
end
end)