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.