I’m trying to change the adornee of a billboard GUI (which is in the PlayerGui) to the part that you click on, but it doesn’t work properly. For some reason, it requires you to click the Preset* adornee first before you can switch the adornee to the other parts.
(The preset is the part I attached the adornee from the start not in testing mode)
local soy = game.ReplicatedStorage.Soy
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Parent.Adornee:FindFirstChild("IsSoy").Value == false and player:WaitForChild("stats"):WaitForChild("Cash").Value >= 10000 then
local stage1 = soy.SoyStage1:Clone()
stage1.Parent = script.Parent.Parent.Parent.Adornee
stage1:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.Adornee.OriginValue.Value.Position))
script.Parent.Parent.Parent.Adornee.OriginValue.Value:Destroy()
player:WaitForChild("stats"):WaitForChild("Cash").Value -= 10000
script.Parent.Parent.Parent.Adornee:FindFirstChild("IsSoy").Value = true
else
return
end
end)
I don’t necessarily see the problem but you can always use prints. I did rewrite it to some extent because as I rewrite code the problem usually becomes present but I truly have no idea. You’d have to just set breakpoints & use printing to your advantage.
Here’s the source I wrote myself.
local players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")
local localplayer = players.LocalPlayer
local soy = repstore:WaitForChild("Soy")
local billboard = script:FindFirstAncestorWhichIsA("BillboardGui")
script.Parent.MouseButton1Up:Connect(function()
if typeof(billboard.Adornee) == 'Instance' then
local isSoy = billboard.Adornee:FindFirstChild("IsSoy")
if typeof(isSoy) == 'Instance' and isSoy:IsA("BoolValue") and isSoy.Value ~= true then
local stats = localplayer:WaitForChild("stats", 5)
local cash = typeof(stats) == 'Instance' and stats:FindFirstChild("Cash")
local origin = typeof(cash) == 'Instance' and cash:IsA("IntValue") and cash.Value >= 1e4 and billboard.Adornee:WaitForChild("OriginValue")
if typeof(origin) == 'Instance' and origin:IsA("ObjectValue") and typeof(origin.Value) == 'Instance' and origin.Value:IsA("BasePart") then
local soyStage1 = soy:WaitForChild("SoyStage1"):Clone()
soyStage1.Parent = billboard.Adornee
soyStage1:SetPrimaryPartCFrame(CFrame.new(origin.Value.Position))
origin.Value:Destroy()
cash.Value -= 1e4 -- is this supposed to be on the client (just trying to clarify because stats usually are server-side)
isSoy.Value = true
end
end
end
end)
The problem is that it is supposed to change the BillboardGui Adornee part to the square I’m clicking (as shown in the video), but for some reason it only works if I click the middle square (red square in video) first. If I click any other square before clicking the middle one, it doesn’t work.