-
What do you want to achieve? I want to make it so that when a button in my tycoon is stepped on, it plays a sound.
-
What is the issue? My current solution produces 0 errors but doesn’t work at all.
-
What solutions have you tried so far? I tried firing an event on the client but it didnt play the sound.
button.PrimaryPart.Touched:Connect(function(hit)
local playButtonSoundEvent = replicatedStorage:FindFirstChild("playButtonSoundEvent")
local buttonPurchaseSound = replicatedStorage:FindFirstChild("buttonPurchaseSound")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
if plot:GetAttribute("Owner") ~= player.UserId then return end
-- TO DO LIST!!! :)
-- Remove currency
-- Check if they have enough
-- Give em the item
-- Code below here that runs means what touched it was plot owner!
-- THE END!!! :(
local itemToBuyId = button:GetAttribute("ITEMTOBUYID")
if not itemToBuyId then warn("goofy man you forget to add an id") return end
for _, item in templateItems:GetChildren() do
if item:GetAttribute("ID") == not itemToBuyId then continue end
-- Correct item found! Wahoo!
-- Clone item and reposition it.
local itemClone = item:Clone()
itemClone.Parent = itemsFolder
local itemCFrame
if itemClone:IsA("Model") then -- What kind of item is the itemClone?
itemCFrame = itemClone:GetPivot() -- Models have no CFrame <:(
elseif itemClone:IsA("BasePart") then
itemCFrame = itemClone.CFrame
end
local relativeItemCFrame = templatePlot.CFrame:ToObjectSpace(itemCFrame)
local worldCFrameOfNewPlot = plot.CFrame:ToWorldSpace(relativeItemCFrame)
if itemClone:IsA("Model") then
itemClone:PivotTo(worldCFrameOfNewPlot)
elseif itemClone:IsA("BasePart") then
itemClone.CFrame = worldCFrameOfNewPlot
end
playButtonSoundEvent:FireClient(player, buttonPurchaseSound)
button:Destroy()
end
end)
This is the event script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local playButtonSoundEvent = replicatedStorage:WaitForChild("playButtonSoundEvent")
local buttonPurchaseSound = replicatedStorage:WaitForChild("buttonPurchaseSound")
playButtonSoundEvent.OnServerEvent:Connect(function(player, buttonPurchaseSound)
buttonPurchaseSound:Play()
print("yes!")
end)
This is what happens:
If you know how I can make this work please please reply down below I have tried fixing this for so long but it’s so hard .