Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you help me with ObjectValue/Sound?

Asked by 9 years ago

Hello everyone, TixyScripter here! I am making a tycoon called Robloxian Rebirth Tycoon II, and I wanted to add sound when you buy something. This is what I got so far with the help of "FearMeIAmLag".

Part I edited below this script! Whole script:

objects = {}
teamcolor = BrickColor.new(script.Parent.Name)
config = script.Parent.Parent.Parent.Configuration
wait(1)

script.Parent.Essentials.Spawn.TeamColor = teamcolor
script.Parent.Essentials.Spawn.BrickColor = teamcolor

script.Parent.Essentials.Collector.Touched:connect(function(hit)
    if hit:FindFirstChild("Cash") then
        script.Parent.Cash.Value = script.Parent.Cash.Value + hit.Cash.Value
        Instance.new("Sparkles",hit).Color=Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255)
        game.Debris:AddItem(hit,0.1)
    end
end)


script.Parent.Essentials.Giver.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then
        if script.Parent.Owner.Value == player then
            if hit.Parent:FindFirstChild("Humanoid") then
                if hit.Parent.Humanoid.Health > 0 then
                    local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
                    if cashmoney ~= nil then 
                        cashmoney.Value = cashmoney.Value + script.Parent.Cash.Value
                        script.Parent.Cash.Value = 0

                    end
                end
            end
        end
    end
end)

script.Parent:WaitForChild("Buttons")
for i,v in pairs(script.Parent.Buttons:GetChildren()) do
    if v:FindFirstChild("Head") then

        local object = script.Parent.Purchases:FindFirstChild(v.Object.Value)
        if object ~= nil then
            objects[object.Name] = object:Clone()
            object:Destroy()
        else
            print("Button: "..v.Name.." is missing its object and has been removed.")
            v.Head.CanCollide = false
            v.Head.Transparency = 1
        end

        if v:FindFirstChild("Dependency") then
            v.Head.CanCollide = false
            v.Head.Transparency = 1
            coroutine.resume(coroutine.create(function()
                if script.Parent.PurchasedObjects:WaitForChild(v.Dependency.Value) then
                    if config.ButtonFadeInDependency.Value == true then
                        for i=1,20 do
                            wait(config.ButtonFadeInTime.Value/20)
                            v.Head.Transparency = v.Head.Transparency - 0.05
                        end
                    end
                    v.Head.CanCollide = true
                    v.Head.Transparency = 0
                end
            end))
        end

        v.Head.Touched:connect(function(hit)
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if v.Head.CanCollide == true then
                if player ~= nil then
                    if script.Parent.Owner.Value == player then
                        if hit.Parent:FindFirstChild("Humanoid") then
                            if hit.Parent.Humanoid.Health > 0 then
                                local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
                                if cashmoney ~= nil then
                                    if cashmoney.Value >= v.Price.Value then
                                        cashmoney.Value = cashmoney.Value - v.Price.Value
                                        objects[v.Object.Value].Parent = script.Parent.PurchasedObjects
                                        game.Players[script.Parent.Owner.Value].PlayerGui.Sound2:Play()   
                                            if config.ButtonExplodeOnBuy.Value == true then
                                            local explosion = Instance.new("Explosion",workspace)
                                            explosion.Position = v.Head.Position
                                            explosion.DestroyJointRadiusPercent = 0
                                            explosion.BlastPressure = 0
                                        end
                                        if config.ButtonFadeOutOnBuy.Value == true then
                                            v.Head.CanCollide = false
                                            coroutine.resume(coroutine.create(function()
                                                for i=1,20 do
                                                    wait(config.ButtonFadeOutTime.Value/20)
                                                    v.Head.Transparency = v.Head.Transparency + 0.05     
                                                end
                                            end))
                                        else
                                            v.Head.CanCollide = false
                                            v.Head.Transparency = 1
                                        end
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end)

    end
end

Part I added midway through:

game.Players[script.Parent.Owner.Value].PlayerGui.Sound2:Play()

Owner is an ObjectValue in the same Parent as the Script, the Value is the Tycoon Owner's name like TixyScripter if I owned the tycoon

The reason for the big part in the middle is so that the Sound only plays for the person who owns the tycoon, since other will be annoyed when hearing all the time, but when I test it, it won't work... It just says in-valid argument?

hierarchy: http://imgur.com/3TGitGF

Error in output:

Workspace.Berezaa's Tycoon Kit.Tycoons.Bright blue.Purchase:79: bad argument #2 to '?' (string expected, got user data) Script 'Workspace.Berezaa's Tycoon Kit.Tycoons.Bright blue.Purchase', Line 79 Stack end

0
What's the exact error? drew1017 330 — 9y
0
@drew1017 Edited, it will show it at the bottom TixyScripter 115 — 9y
0
You're not showing us any of the script. Nickoakz 231 — 9y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

ObjectsValues store references to Objects, not strings. script.Parent.Owner.Value is a Player Object, not the Name of that Player, even though only their name shows up in the Properties section.

Try changing the line you added to this:

script.Parent.Owner.Value.PlayerGui.Sound2:Play()
0
Well, the same error happened. No sound and the button didn't go away, it just spawned the model that comes when you buy it from the button.. Do you think there is anyway that I can make the sound just in an area, like if your close to it you here it more the close you are? I think that would be easier? TixyScripter 115 — 9y
0
Which exact line in your code is causing the error? I'm not familiar with berezaa's tycoon kit. adark 5487 — 9y
0
Line 79 TixyScripter 115 — 9y
0
That's the line you added, however. I'm really clueless as to what could be erroring here. adark 5487 — 9y
Ad

Answer this question