So I’m trying to understand why this function is not being triggered from a long time but still idk.
local Model = script.Parent
local Config = Model.Configuration
local userId = Config.userId.Value
local FriendBot = script.Parent.Parent.Name
local button = script.Parent.Parent.Parent:FindFirstChild(FriendBot .. "Button") ---------------------- nameee
local Loader
if Config.AutoUpdateLoader.Value then
Loader = require(552034302)
else
Loader = require(script.MainModule)
end
-------------------------------------------------------------------------------------
Loader:updateModel(Model, Config.userId.Value)
button.Head.Touched:Connect(function()
print("Touched")
while userId == 2383848373 do
task.wait(0.1)
end
Loader:updateModel(Model, Config.userId.Value)
print("AVATAR LOADED")
end)
The script need to load the avatar of a user from his id to a dummy using the Loader:updateModel(Model, Config.userId.Value) function. That’s working but I want to trigger it when the button is touched so that’s what I’ve made. Can anyone tell me where I’m wrong and why the button.Head.Touched:Connect(function() function is not being called. I tested it and the button is being recognized and have a children called “Head”. Thanks for the help, probably that’s simple one but I’m new to scripting and that’s not happening for the first time to me.
So the i think the reason why it would never en is becuase your not checking if it has a humanoid and as soon as anyparts touches it the loop woill began but since there is a userid varible is set to the number you have to set in a task.spawn(function() and have a if statement checking for a humanoid
local Model = script.Parent
local Config = Model.Configuration
local userId = Config.userId.Value
local FriendBot = script.Parent.Parent.Name
local button = script.Parent.Parent.Parent:FindFirstChild(FriendBot .. "Button") ---------------------- nameee
local Loader
if Config.AutoUpdateLoader.Value then
Loader = require(552034302)
else
Loader = require(script.MainModule)
end
-------------------------------------------------------------------------------------
Loader:updateModel(Model, Config.userId.Value)
button.Head.Touched:Connect(function(hit)
If hit.Parent:FindFirstChild("Humanoid")
print("Touched")
task.spawn(function()
while userId == 2383848373 do
task.wait(0.1)
end
end)
Loader:updateModel(Model, Config.userId.Value)
print("AVATAR LOADED")
end
end)
Ii don’t know if it will help, but in my experience i struggle a bit with OnTouch events. They only activate if the part moves and touches the other, which means that anchored parts or parts created that are already touching the part won’t trigger the event
You said there that the button have a children called “Head”. You saw that trought the print function or you’re saying that you added a children called “Head”?
If it was from printing, the Head is the part of the character that is touching the button
The “Head” is already there:
Also the script inside the head have a function that works:
function onTouched(hit)
if ting == 0 then
ting = 1
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://5613553529"
local owner = factory.OwnerName.Value
local check = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:FindFirstChild(owner)
if check ~= nil then
local user = game.Players:GetPlayerFromCharacter(hit.Parent)
if owner == user.Name then
local stats = user:findFirstChild("leaderstats")
if stats ~= nil then
local cost = 5 ------------------------------------------------------------------------------ PRIZE
if player.leaderstats.Money.Value >= cost then
script.Parent.Parent:SetPrimaryPartCFrame(newPivot)
Friend2Button:SetPrimaryPartCFrame(rightPivot) -------------------------------pos
Friend3Button:SetPrimaryPartCFrame(rightPivot2)
player.leaderstats.Money.Value -= cost
local machine = factory.Stuff.Friend1.Value:Clone() --------------------------------------------------------------------- NAME
machine.Parent = factory
machine:MakeJoints()
local button = script.Parent.Parent
button.Head.Transparency = 1
button.Head.Glow:Destroy()
button.Head.Union:Destroy()
button.Head.BillboardGui:Destroy()
button.Head.BillboardGui2:Destroy()
local Friend = game.Workspace["Abonded Tycoon"].All.Tycoon.Friend1 ---------------------------------------------------------------- NAME
sound.Parent = game.Workspace["Abonded Tycoon"].All.Tycoon:WaitForChild(Friend.Name)["Study Desk"].SoundPart
sound.RollOffMaxDistance = 30
while true do
local player = game.Players:FindFirstChild(owner)
local loadingBar = Friend.Rig.PartUI.BillboardGui.CanvasGroup.Progress
local Timer = Friend.Rig.PartUI.BillboardGui2
local n = math.round(timerVal)
local timersize = n
local barsize = loadingBar.Size.X.Scale
barsize = 0.001
loadingBar.Size = UDim2.new(barsize, loadingBar.Size.X.Offset, loadingBar.Size.Y.Scale, loadingBar.Size.Y.Offset)
Timer.Text.Text = timersize .."s"
for i = 1, 100, 1 do
Timer.Text.Text = math.round(timersize * 10)/10 .. "s"
barsize += 0.01
loadingBar.Size = UDim2.new(barsize, loadingBar.Size.X.Offset, loadingBar.Size.Y.Scale, loadingBar.Size.Y.Offset)
timersize -= n/100
task.wait(n/100)
end
Timer.Text.Text = "0s"
local BanEvent = game:GetService('ReplicatedStorage'):WaitForChild('BanEvent')
BanEvent:FireClient(player)
sound:Play()
task.wait(0.619)
sound:Stop()
end
end
end
end
end
ting = 0
end
end
script.Parent.Touched:connect(onTouched)
And I don’t understand why this script works but the second one that I made the post for doesn’t.
I tried your code but still it doesn’t work. Also I don’t think the humanoid is a problem since the head part inside the button is anchored. That means only non anchored objects can trigger the event and even them can’t trigger it since the print line is not running.
I made it like this because there are more then one friend and I will make even more so to win some time I made it like that. Also the part is not getting called “FriendBotButton” because FriendBot is equal to FriendX where X is a number.
I finally made it! So I didn’t solve the problem with the Touched:Connect(function() I just remembered that this script is being triggered when the player touch the button so here is the new script:
local Model = script.Parent
local Config = Model.Configuration
local userId = Config.userId.Value
local FriendBot = script.Parent.Parent.Name
local button = script.Parent.Parent.Parent:FindFirstChild(FriendBot .. "Button")
local Loader
if Config.AutoUpdateLoader.Value then
Loader = require(552034302)
else
Loader = require(script.MainModule)
end
-------------------------------------------------------------------------------------
Loader:updateModel(Model, Config.userId.Value)
task.spawn(function()
while userId == 2383848373 do
task.wait(0.1)
end
end)
task.wait(1)
Loader:updateModel(Model, Config.userId.Value)
print("DONE")
I’m using the function that @MrNobodyDev said to use:
Thanks to everyone who helped, I really appreciate it!