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

Script works in studio test but not in the actual game?

Asked by 6 years ago

This script is supposed to play a sound when touching a brick, while stopping other sounds

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
    game.Players[hit.Parent.Name].PlayerGui.Sound1.Volume = 1
    game.Players[hit.Parent.Name].PlayerGui.Sound1:Play()
    game.Players[hit.Parent.Name].PlayerGui.Sound2:Stop()
end
end)

However, when tested on roblox studio it works perfectly fine but when in the actual roblox game it fails to do anything.

I'm new to scripting so it's been a pain trying to figure out whats wrong with this script, please send help!

1 answer

Log in to vote
0
Answered by 6 years ago

Try using GetPlayerFromCharacter, like so:

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
    player = game.Player:GetPlayerFromCharacter(hit.Parent)
    player.PlayerGui.Sound1.Volume = 1
    player.PlayerGui.Sound1:Play()
    player.PlayerGui.Sound2:Stop()
end
end)
0
Using that script it stops working entirely both in game and in studio DannyKyun 14 — 6y
Ad

Answer this question