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

I need a Level Buying system, can you help me?

Asked by 4 years ago

I am working on a game and I want the player to be able a passageway to the next area using coins. I have tried going through a tutorial and It didn't work and I would really appreciate a helping answer.

Here is my ontouched Script:

local cooldown = false

function onTouched(hit)
    if cooldown == false then
        if hit.Parent:FindFirstChild("Humanoid") then
            cooldown = true

            local BuyGui = script.Parent.Buy
            BuyGui:Clone().Parent = game.Players:FindFirstChild(hit.Parent.Name).PlayerGui

            wait(5)
            cooldown = false
        end
    end
end

script.Parent.Touched:Connect(onTouched)

Gui Script:

local BuyButton = script.Parent.BuyButton
local CancelButton = script.Parent.CancelButton
local Click = script.Parent.Click
local MainFrame = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BuyPassage = game.ReplicatedStorage:WaitForChild("BuyPassage")
local player = game.Players.LocalPlayer

BuyButton.MouseButton1Click:Connect(function()
    Click:Play()
    MainFrame.Visible = false
    BuyPassage:FireClient(player, "Spawn")
end)

CancelButton.MouseButton1Click:Connect(function()
    Click:Play()
    MainFrame.Visible = false
end)

ServerScriptService RemoteEvent Handler:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BuyPassage = Instance.new("RemoteEvent", ReplicatedStorage)
BuyPassage.Name = "BuyPassage"


function OnFiredEvent(Player, Passage)
    if Passage == "Spawn" then
        game.Players:FindFirstChild(Player):WaitForChild("leaderstats").Coins.Value = game.Players:FindFirstChild(Player):WaitForChild("leaderstats").Coins.Value - 100
        game.Workspace.Map.Spawn.Passage.Part.CanCollide = false
        game.Workspace.Map.Spawn.Passage.Part.Transparency = 1
        wait(1)
        game.Workspace.Map.Spawn.Passage.Part.CanCollide = true
        game.Workspace.Map.Spawn.Passage.Part.Transparency = 0.75
    end
end

BuyPassage.OnClientEvent:connect(OnFiredEvent())

If you know how to help me please tell me.

0
When you say that it didn't work, what do you mean? As in, how did you test it, what happened, and what were you expecting to happen instead? Please also post any output from the scripts. gskw 1046 — 4y

Answer this question