#Need coin to disappear after touching it

1 messages · Page 1 of 1 (latest)

tulip mauve
#

I have a script that makes it to where you speed up after touching a coin. That works fine. I duplicated that coin, and put it on the opposite side of the map. The script still works, but only one coin will disappear. The same coin disappears regardless of which coin is touched first too.

I want the coin that is touched to disappear, and not only one coin. I would like the script to work for both coins at once instead of having to put a separate script in each of them.

quaint crystalBOT
#

studio** You are now Level 7! **studio

tulip mauve
#
local PowerUp = game.Workspace.PowerUpCoins.SpeedUpCoin -- The coin, cylinder in workspace that grants powerups.
local Speedup = PowerUp:GetAttribute("SpeedUpAmount") -- The amount of speed a player will be granted. 
local Duration = PowerUp:GetAttribute("Duration") -- The duration the player will retain the new powers for.
local CanTouch = true

local function GivePowers(part) -- Handles the interaction between a player and the power-up coin.
    local hum = part.Parent:FindFirstChild("Humanoid") -- Finds the player in workspace. 

    if hum and CanTouch then -- If a player touches the coin, the function will run. 
        CanTouch = false -- Stops the script from running multiple times from being touched. 
        local originalWalkSpeed = hum.WalkSpeed -- Original walkspeed for players, 16
        
        hum.WalkSpeed = Speedup -- Speed the player is granted
        PowerUp.Transparency = 1.0 -- Makes the coin invisible after being touched
        PowerUp.CanCollide = false -- Players cannot touch the coin while it is invisible
        
        task.wait(Duration) -- The duration the player will retain the speed buff for
        
        PowerUp.Transparency = 0.5 -- Coin is visible after duration ends
        PowerUp.CanCollide = true -- Coin can be touched again
        hum.WalkSpeed = originalWalkSpeed -- Original speed value restored
        
        CanTouch = true -- The coin can be touched by player to execute the script again
    end
end

for k, n in pairs(game.Workspace.PowerUpCoins:GetChildren()) do -- For loop that looks through the workspace to find every SpeedUpCoin I have created. 
    if n.Name == "SpeedUpCoin" then -- If the name of the part it finds is "SpeedUpCoin" then the code below will run. 
        n.Touched:Connect(GivePowers) -- Connects the Touched function to the DealDamage function. 
    end
end
gritty sinew
#

do both coins have the same name?

keen hawk
keen hawk
#

It'll make the process much easier and smoother both in gameplay and development

tulip mauve