I am currently trying to expand upon one of my test powerups by making a theme play when it is touched.
--Declarations-----
local speedBoost = script.Parent
local boostSpeed = 48
local cooldown = 10
local speedDuration = 5
local canRun = true
-------------------------------
---------Part controlling the powerup effect------------
local function handleTouch(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChild('Humanoid')
if humanoid and canRun then
canRun = false
humanoid.WalkSpeed = boostSpeed
speedBoost.Transparency = .5
wait(speedDuration)
humanoid.WalkSpeed = 16
wait(cooldown)
speedBoost.Transparency = 0
canRun = true
end
end
speedBoost.Touched:connect(handleTouch)
-----------------------------------------------------
--------------Part attempting to control music-----------
speedBoost.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local plrgui = game:GetService('Players').LocalPlayer.PlayerGui
print(player)
local starMan = plrgui.starMan
starMan:Play()
end
end)
-------------------------------------------------------------------------
This works only while in Studio Play mode for the obvious reason of LocalPlayer being used. When I try to link it to the player's GUI by replacing LocalPlayer with the variable player I get an error stating that player is not a valid member of Players, despite it clearly printing out the name of the character (In Studio's case, Player1) as such
--------------Part attempting to control music-----------
speedBoost.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local plrgui = game:GetService('Players').player.PlayerGui --Breaks
print(player) --Prints Player1
local starMan = plrgui.starMan
starMan:Play()
end
end)
Having the server call local sounds from a player GUI works perfectly, I've already done the testing in the Server mode of Studio where these put into the command bar
game.Players.Player1.PlayerGui.starMan:Play() plays the theme on my computer and
game.Players.Player.PlayerGui.starMan:Play()Even played it on my IPad through the Roblox Developer app.
At this point I'm stuck with what to do, I can't progress with my future plans for the powerup without the music being able to play in its own right.
Any help is appreciated! Thanks
~MBacon15

1 comment
soundposition?