You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to fix some cloned textbuttons not working. -
What is the issue? Include screenshots / videos if possible!
When i clone a imagelabel with the textbutton inside of it, i cant use .Activated:Connect() on the textbutton.
It does not work and gives no errors. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked at the devforum, and i found some topics that were litterally my question, but they did not help me.
This one didnt even give a answer.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
I have two scripts: my shophandler and a serverside script with the name “setup”, which makes and deletes the textbuttons.
The typechanged remoteevent is the remoteevent that connects the setup script with the shophandler. It fires if the player either presses the left or right arrow.
“Setup”
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
--local dataModule = require(game.ServerStorage.PlayerData:FindFirstChild(plr.Name))
--dataModule.Load()
local DataStore2 = require(ReplicatedStorage.Modules.DataStore2)
local rawPlayerData = DataStore2("data",plr)
local playerData = rawPlayerData:Get()
--local furnitureData = dataModule.ReturnData()
local items = ReplicatedStorage.Items:FindFirstChild("Furniture")
local TypeChanged = script.Parent.Parent:FindFirstChild("TypeChanged")
function getOrientation(cf)
local Part = Instance.new('Part')
Part.CFrame = cf
local a = Part.Orientation
Part:Destroy()
return a
end
function setup(itemType)
for i, v in pairs(script.Parent:GetChildren()) do
if v.Name == "Item" then
v:Destroy()
end
end
if itemType == "furniture" or itemType == "colors" or itemType == "materials" then
items = ReplicatedStorage.Items:FindFirstChild(itemType)
for i, v in pairs(items:GetChildren()) do
local frame = script.Item:Clone()
frame.Parent = script.Parent
local viewport = frame.ViewportFrame
local item = v:Clone()
item.Parent = viewport
local part = item.PrimaryPart
local camera = Instance.new("Camera", viewport)
camera.CFrame = part.CFrame + (part.CFrame.LookVector*(part.Size.X*1.76))
camera.CFrame = CFrame.lookAt(camera.CFrame.Position, part.Position)
viewport.CurrentCamera = camera
local part2 = part:Clone()
part2.Parent = workspace
--part3 = Instance.new("Part",workspace)
--part3.Material = Enum.Material.Neon
--part3.BrickColor = BrickColor.new("Really red")
--part3.Anchored = true
--part3.CFrame = camera.CFrame
if playerData[itemType] then
local itemData = playerData[itemType]
if itemData[v.Name] then
if itemData[v.Name][1] == "equipped" then
frame.ImageColor3 = Color3.fromRGB(0, 40, 13)
elseif itemData[v.Name][1] == "unequipped" then
frame.ImageColor3 = Color3.fromRGB(40, 0, 0)
end
end
end
end
end
end
TypeChanged.OnServerEvent:Connect(function(plr, itemType)
setup(itemType)
end)
setup("furniture")
“ShopHandler” I’dd suggest you look at line 177, that is the ConnectButtons() function used to well… connect the buttons.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
local plrData = ReplicatedStorage:WaitForChild("PlayerData"):WaitForChild(game.Players.LocalPlayer.Name)
local BuyItem = plrData:WaitForChild("BuyItem")
local ReturnInfo = plrData:FindFirstChild("ReturnInfo")
local ChangeData = plrData:FindFirstChild("ChangeData")
local TypeChanged = script.Parent:FindFirstChild("TypeChanged")
local RequestPlacement = ReplicatedStorage:WaitForChild("RequestPlacement")
local DataStore2 = require(ReplicatedStorage.Modules.DataStore2)
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local frame = script.Parent
local req1 = require(script.ItemData)
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local equip = frame.Equip
local buy = frame.Buy
local button = frame.Parent.HouseButton
local teleport = frame.Teleport
local db = true
local opened = true
local placing = false
local typeChange = false
local lastEquipped
local currentType = "furniture"
local currentTypeNumberArrows = 1
local show = workspace.HouseShow
local camera = workspace.CurrentCamera
local cameraPart = show.CameraPart
-- frame = script.Parent.Parent
local scrollingFrame = frame.ScrollingFrame
local startingPos = frame.Position
local downPos = startingPos + UDim2.new(0,0, 0, 1000)
frame.Position = downPos
local waitt = 0.5
wait(1)
local placementModule = require(game.ReplicatedStorage.Modules:FindFirstChild("PlacementModuleV3"))
local placementInfo = placementModule.new(
1,
ReplicatedStorage.Items.furniture,
Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.Q, Enum.KeyCode.E,
Enum.KeyCode.ButtonR1, Enum.KeyCode.ButtonX, Enum.KeyCode.DPadUp, Enum.KeyCode.DPadDown
)
local plr = game.Players.LocalPlayer
local mouse = player:GetMouse()
placementModule:editAttribute("FloorStep", 1)
placementModule:editAttribute("EnableFloors", true)
placementModule:editAttribute("RotationStep", 45)
mobile = false
if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface() then
--mobile = true
end
local lastestSelected
function returnItemDataWithType(changeType)
local oldCurrentType = currentType
if changeType then
currentType = changeType
end
if currentType == "furniture" then
return {ReturnInfo:InvokeServer()[2], req1.furniture}
elseif currentType == "materials" then
return {ReturnInfo:InvokeServer()[3], req1.material}
elseif currentType == "colors" then
return {ReturnInfo:InvokeServer()[4], req1.colors}
elseif currentType == "effects" then
return {ReturnInfo:InvokeServer()[5], req1.effects}
elseif currentType == "death_effects" then
return {ReturnInfo:InvokeServer()[6], req1.death_effects}
elseif currentType == "pets" then
return {ReturnInfo:InvokeServer()[7], req1.pets}
end
currentType = oldCurrentType
end
function changeCurrentType(direction)
if direction == "left" then
currentTypeNumberArrows = currentTypeNumberArrows - 1
if currentTypeNumberArrows < 1 then
currentTypeNumberArrows = 6
end
elseif direction == "right" then
currentTypeNumberArrows = currentTypeNumberArrows + 1
if currentTypeNumberArrows > 6 then
currentTypeNumberArrows = 1
end
end
if currentTypeNumberArrows == 1 then
currentType = "furniture"
elseif currentTypeNumberArrows == 2 then
currentType = "materials"
elseif currentTypeNumberArrows == 3 then
currentType = "colors"
elseif currentTypeNumberArrows == 4 then
currentType = "effects"
elseif currentTypeNumberArrows == 5 then
currentType = "death_effects"
elseif currentTypeNumberArrows == 6 then
currentType = "pets"
end
end
function visualizeFurniture()
if plr then
for i, v in pairs(show:GetChildren()) do
if v.Name ~= "Plate" and v.Name ~= "Part" and v.Name ~= "SpawnLocation" then
v:Destroy()
end
end
local house = "HouseT"..ReturnInfo:InvokeServer()[8]
local c = workspace.Houses[house]:Clone()
c.Parent = show
c:PivotTo(show.Plate.CFrame)
local furnitureData = returnItemDataWithType("furniture")[1]
for i2, v2 in pairs(furnitureData) do
if i2 ~= "#equipped" then
if v2[1] == "equipped" then
local furniture = ReplicatedStorage.Items.furniture:FindFirstChild(i2):Clone()
if furniture then
furniture:SetPrimaryPartCFrame(CFrame.new(v2[2][1],v2[2][2],v2[2][3])*CFrame.Angles(math.rad(v2[3][1]),math.rad(v2[3][2]),math.rad(v2[3][3]))+show.Plate.Position)
furniture.Parent = show
furniture.PrimaryPart.Anchored = true
end
end
end
end
end
end
function changeTypeInfoText()
if currentType == "furniture" then
typeChange = false
placementInfo = placementModule.new(
1,
ReplicatedStorage.Items.furniture,
Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.Q, Enum.KeyCode.E,
Enum.KeyCode.ButtonR1, Enum.KeyCode.ButtonX, Enum.KeyCode.DPadUp, Enum.KeyCode.DPadDown
)
local equipped = returnItemDataWithType("furniture")[1]["#equipped"]
if not equipped then
equipped = 0
end
frame.TypeInfo.Text = "Furniture "..equipped.."/"..ReturnInfo:InvokeServer()[8].." Max scales with house tier."
else
if ReplicatedStorage.Items:FindFirstChild(currentType) then
--placementInfo = placementModule.new(
-- 1,
-- ReplicatedStorage.Items[currentType],
-- Enum.KeyCode.R, Enum.KeyCode.X, Enum.KeyCode.Q, Enum.KeyCode.E,
-- Enum.KeyCode.ButtonR1, Enum.KeyCode.ButtonX, Enum.KeyCode.DPadUp, Enum.KeyCode.DPadDown
--)
typeChange = false
end
local t = currentType
local fl = string.sub(t, 1, 1)
fl = fl:upper() -- Or :lower() depending on what you want to do
t = fl..string.sub(t, 2, -1)
frame.TypeInfo.Text = t
end
end
function connectButtons()
for i, v in pairs(scrollingFrame:GetChildren()) do
if v.Name == "Item" then
local viewPort = v.ViewportFrame
local ItemInFrame = viewPort:GetChildren()[1]
local itemData = returnItemDataWithType()[1]
local itemInfo = returnItemDataWithType()[2]
local bought = itemData[ItemInFrame.Name]
if itemInfo == nil then
return
end
--if bought then
-- v.ImageColor3 = Color3.fromRGB(v.ImageColor3.R + 20, v.ImageColor3.G + 20 , v.ImageColor3.B + 20 )
--end
v.SelectBtn.Activated:Connect(function()
print("hii")
if placing then
placementInfo:terminate()
placing = false
ChangeData:FireServer("equip", lastestSelected.ViewportFrame.Name, "unequipped", currentType)
end
local bought = itemData[ItemInFrame.Name]
local item = itemInfo[ItemInFrame.Name]
lastestSelected = v
frame.Info.Text = "Cost = "..item[1].." Description = "..item[3]
equip.TextLabel.Text = "Equip"
if not bought then
buy.TextLabel.Text = 'Buy "'..item[2]..'"'
else
buy.TextLabel.Text = '"'..item[2]..'" Bought'
if bought[1] == "equipped" then
equip.TextLabel.Text = "Unequip"
v.ImageColor3 = Color3.fromRGB(0, 40, 13)
elseif bought[1] == "unequipped" then
equip.TextLabel.Text = "Equip"
v.ImageColor3 = Color3.fromRGB(40, 0, 0)
end
end
end)
end
end
end
buy.Activated:Connect(function()
if lastestSelected then
local viewPort = lastestSelected.ViewportFrame
local ItemInFrame = viewPort:GetChildren()[1]
local itemInfo = returnItemDataWithType()[2]
local item = itemInfo[ItemInFrame.Name]
local success = BuyItem:InvokeServer(item, ItemInFrame.Name, currentType)
if success then
lastestSelected.ImageColor3 = Color3.fromRGB(40, 0, 0)
buy.TextLabel.Text = '"'..item[2]..'" Bought'
end
end
end)
equip.Activated:Connect(function()
if lastestSelected then
local viewPort = lastestSelected.ViewportFrame
local ItemInFrame = viewPort:GetChildren()[1]
lastEquipped = ItemInFrame
--local itemData = returnItemDataWithType()[2]
local bought = returnItemDataWithType()[1][ItemInFrame.Name]
if bought then
if bought[1] == "unequipped" then
changeTypeInfoText()
equip.TextLabel.Text = "Unequip"
--ChangeData:FireServer("equip", ItemInFrame.Name, "equipped")
placementInfo:activate(ItemInFrame.Name, workspace.HouseShow.Plate.itemHolder, workspace.HouseShow.Plate, false, false, false)
placing = true
elseif bought[1] == "equipped" then
changeTypeInfoText()
lastestSelected.ImageColor3 = Color3.fromRGB(40, 0, 0)
equip.TextLabel.Text = "Equip"
ChangeData:FireServer("equip", ItemInFrame.Name, "unequipped", currentType)
visualizeFurniture()
end
end
end
end)
teleport.Activated:Connect(function()
if player.Team == game.Teams["Lobby"] then
if not mobile then
camera.CameraType = Enum.CameraType.Track
else
camera.CameraType = Enum.CameraType.Follow
end
local char = plr.Character
local hrp = char:FindFirstChild("HumanoidRootPart")
hrp.CFrame = show.Plate.CFrame + Vector3.new(0, 3, 0)
end
end)
mouse.Button1Down:Connect(function()
if lastEquipped and placing then
lastestSelected.ImageColor3 = Color3.fromRGB(0, 40, 13)
ChangeData:FireServer("equip", lastEquipped.Name, "equipped", currentType)
placementInfo:requestPlacement(RequestPlacement)
placing = false
visualizeFurniture()
end
--placementInfo:terminate()
end)
button.Activated:Connect(function()
if db then
db = false
if opened then
camera.CameraType = Enum.CameraType.Scriptable
local tween = TweenService:Create(camera, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = cameraPart.CFrame})
tween:Play()
tween.Completed:Wait()
camera.CFrame = cameraPart.CFrame
frame:TweenPosition(startingPos, Enum.EasingDirection.Out, Enum.EasingStyle.Quint, waitt)
elseif not opened then
if not mobile then
camera.CameraType = Enum.CameraType.Track
else
camera.CameraType = Enum.CameraType.Follow
end
frame:TweenPosition(downPos, Enum.EasingDirection.In, Enum.EasingStyle.Quint, waitt)
end
task.wait(waitt)
opened = not opened
db = true
end
end)
frame.ArrowLeft.Activated:Connect(function()
typeChange = true
changeCurrentType("left")
changeTypeInfoText()
TypeChanged:FireServer(currentType)
task.wait(0.1)
connectButtons()
end)
frame.ArrowRight.Activated:Connect(function()
typeChange = true
changeCurrentType("right")
changeTypeInfoText()
TypeChanged:FireServer(currentType)
task.wait(1)
connectButtons()
end)
mouse.Move:Connect(function()
if camera.CameraType == Enum.CameraType.Scriptable then
if camera.CFrame.Position == cameraPart.Position then
local x = mouse.X/40--*(camera.ViewportSize.X/2)
local y = mouse.Y/40--*(camera.ViewportSize.Y/2)
local tween = TweenService:Create(camera, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {CFrame = cameraPart.CFrame * CFrame.Angles(-math.rad(y), -math.rad(x), math.rad(0))})
tween:Play()
end
end
end)
coroutine.wrap(function()
visualizeFurniture()
changeTypeInfoText()
TypeChanged:FireServer(currentType)
task.wait(1)
connectButtons()
TypeChanged:FireServer(currentType)
while task.wait(10) do
visualizeFurniture()
end
end)()
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.