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

Is it possible for this script to work more than once?

Asked by 9 years ago

Hello! I have made an Easter Egg in my place and I made a Gui that will pop up when the brick is touched, saying: You found an Easter Egg, The SkyHook! the Gui is in my starterGui called EggGui. It will pop up and play the victory sound but after I reset and go to the Brick and it doesn't pop up again. any way it can happen more than once?

here is the script:

function onTouched(hit)
game.Players.LocalPlayer.PlayerGui.EggGui.Frame.Visible = true
game.Players.LocalPlayer.PlayerGui.EggGui.Sound:Play()
wait(2)
game.Players.LocalPlayer.PlayerGui.EggGui.Frame.Visible = false

end

connection = script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
2
Answered by 9 years ago

Don't save it into a variable, try this:

script.Parent.Touched:connect(function(hit)
    game.Players.LocalPlayer.PlayerGui.EggGui.Frame.Visible = true
    game.Players.LocalPlayer.PlayerGui.EggGui.Sound:Play()
    wait(2)
    game.Players.LocalPlayer.PlayerGui.EggGui.Frame.Visible = false
end)

Replace the script with that and it should work. I made it connect to an anonymous function to save a bit of space. I'm not sure why you decided the save the connection in a variable, if you just declare it like I did it will work fine. I also see that you're using the LocalPlayer object, this can only be used in LocalScripts. So that may also be why it isn't working.

0
this worked but I have a problem; It doesn't work in the actual game! it works in studio though. Any help? minikitkat 687 — 9y
0
I edited my answer Norshine 88 — 9y
0
Changing it to a LocalScript broke it all together! But there isn't anything in my output! minikitkat 687 — 9y
1
You don't change it to a LocalScript! You use something else besides LocalPlayer, like game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui. Norshine 88 — 9y
View all comments (2 more)
0
Yahoo!! It worked!!! Thank you! I guess I misread you the first time! Thanks again! minikitkat 687 — 9y
0
Your welcome Norshine 88 — 9y
Ad

Answer this question