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

How Would I Change This From An On Touched Event To An On Clicked Event?

Asked by 4 years ago

Before You Decide To Take My Post Down Please Know That I Am Not Allowed On The Roblox Dev Website.

I'm Not Sure How To Change This On Touched To An On Clicked.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
local Sold = RemoteEvent.ItemSold

local Debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Player.leaderstats.Gems.Value >= 5000 then
            if Debounce == false then
            Debounce = true
            Player.leaderstats.Rebirth.Value = Player.leaderstats.Rebirth.Value + 1
            Player.leaderstats.Gems.Value = Player.leaderstats.Gems.Value - 5000
            script.CashRegister:Play()
            wait(5)
            Debounce = false
            end 

        end
    end

end)
0
Is This A Local Script Or a Server-Side Script? crueluu 169 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

You can use a click detector which has two separate events for left mouse click and right mouse click. The mouse click event also supports other platforms.

local part = script.Parent;
local clickDetector = Instance.new('ClickDetector', part);

clickDetector.MouseClick:connect(function(player)
    --player parameter returns the player instance of the person who clicked
end)
Ad

Answer this question