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

please help, script that plays a song, changes camera, and opens a gui on touch wont work?

Asked by 6 years ago

I'm new to scripting, but i've tried hours on this and nothing will work.. so far in studio the changing camera part works and changing song part works, but only in studio, not in game. so nothing of this works, but i get no errors! can anyone please tell me problems with the script, i need help

debounce = false   
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and debounce == false then
        debounce = true
        player:WaitForChild("PlayerGui").Credits.Frame.Visible = true
        debounce = false
    end
end

local Camera = game.workspace.CurrentCamera
script.Parent.Touched:Connect(function (hit)

Camera.CameraType = "Scriptable"
Camera.CFrame = game.workspace.CamPart2.CFrame

end)

local debounce = false
Music = script.credits
STAR = game.SoundService.STAR
script.Parent.Touched:connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
debounce = true
Music:Play()
STAR:Pause()
end)
local debounce = false
script.Parent.Touched:Connect(function  (hit)
    debounce = true
    game.Workspace.mainwallz.CanCollide = true
end)
0
Because the CurrentCamera is client sided. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This doesn't work because you used a server script, the camera, guis and everything related to the player can only be accessed with a local script. Try using a local script instead, and place it in the StarterPlayerScripts. And you can connect a function by its name, not by its argument (the thing in parenthesis).

debounce = false   
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and debounce == false then
        debounce = true
        player:WaitForChild("PlayerGui").Credits.Frame.Visible = true
        debounce = false
    end
end

local Camera = game.workspace.CurrentCamera
workspace.PARTHERE.Touched:Connect(onTouched)

Camera.CameraType = "Scriptable"
Camera.CFrame = game.workspace.CamPart2.CFrame

end)

local debounce = false
Music = script.credits
STAR = game.SoundService.STAR
workspace.PARTHERE.Touched:connect(function(onTouched)
if not hit.Parent:FindFirstChild("Humanoid") then return end
debounce = true
Music:Play()
STAR:Pause()
end)
local debounce = false
workspace.PARTHERE.Touched:Connect(onTouched)
    debounce = true
    game.Workspace.mainwallz.CanCollide = true
end)
0
thank u so much bowsercow 20 — 6y
Ad

Answer this question