I’m trying to do a client side sound effect and animation pop up whenever I touch / collect a coin. However though, the script seems to never run because every time I touch the coin it just doesn’t register. I’m not sure if I have to put this local script in starterplayerscripts or I’m doing this completely wrong. But everytime I collect a coin the animation nor sound plays. I’ve tried making it into a function like so – Local Script by the way inside of the part in workspace.
local function onTouch()
print("Started")
local coinsound = game.ReplicatedStorage.Coin
local sound = coinsound:Clone()
sound.Parent = workspace
sound:Play()
print("Sound Play")
local r = Random.new()
local Time = 0.25
local ts = game:GetService('TweenService')
local clonedGui = game.ReplicatedStorage.PopUpAnimations.Coin:Clone()
clonedGui.Parent = game.Players.LocalPlayer.PlayerGui.Main
clonedGui.Rotation = math.random(-50, 50)
clonedGui.Position = UDim2.new(r:NextNumber(0,1), 0, 1, 0)
clonedGui:TweenPosition(UDim2.new(r:NextNumber(0, 1), 0, r:NextNumber(0, 0.6), 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, Time)
local rotationTween = ts:Create(clonedGui, TweenInfo.new(1), {Rotation = math.random(-90, 90)})
rotationTween:Play()
wait(1)
local tween = ts:Create(clonedGui, TweenInfo.new(1), {ImageTransparency = 1})
tween:Play()
wait(3)
clonedGui:Destroy()
wait(3)
sound:Destroy()
end
script.Parent.Touched:Connect(onTouch)
Then another solution I tried was – This time it was in StarterPlayerScripts
local function onTouch()
print("Started")
local coinsound = game.ReplicatedStorage.Coin
local sound = coinsound:Clone()
sound.Parent = workspace
sound:Play()
print("Sound Play")
local r = Random.new()
local Time = 0.25
local ts = game:GetService('TweenService')
local clonedGui = game.ReplicatedStorage.PopUpAnimations.Coin:Clone()
clonedGui.Parent = game.Players.LocalPlayer.PlayerGui.Main
clonedGui.Rotation = math.random(-50, 50)
clonedGui.Position = UDim2.new(r:NextNumber(0,1), 0, 1, 0)
clonedGui:TweenPosition(UDim2.new(r:NextNumber(0, 1), 0, r:NextNumber(0, 0.6), 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, Time)
local rotationTween = ts:Create(clonedGui, TweenInfo.new(1), {Rotation = math.random(-90, 90)})
rotationTween:Play()
wait(1)
local tween = ts:Create(clonedGui, TweenInfo.new(1), {ImageTransparency = 1})
tween:Play()
wait(3)
clonedGui:Destroy()
wait(3)
sound:Destroy()
end
repeat wait() until workspace["Map1 Coins"] == nil
if workspace["Map1 Coins"] == nil then
local map1 = workspace["Map1 Coins"]
local coins = map1:GetChildren()
coins.Touched:Connect(onTouch)
end
but the repeat wait until workspace[“Map1 Coins”] didn’t work at all.