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

Script won't control everyone's camera?

Asked by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

Hello. I'm making a game where there's a voting system. When the voting is done, everyone's camera should be placed back to normal. But it doesn't even do that. (There are no error outputs.) I'm using a BindableEvent to get in contact with a LocalScript from a regular script. Here's my following scripts:

Fire BinEvent: (Regular Script in StarterGUI)

local remEvent = game.ReplicatedStorage.Remotes:WaitForChild("RemoteEvent")
local remEvent2 = game.ReplicatedStorage.Remotes:WaitForChild("RemoteEvent2")
local remEvent3 = game.ReplicatedStorage.Remotes:WaitForChild("RemoteEvent3")
local binEvent = game.ReplicatedStorage.Bindables:WaitForChild("Event")
local val = script.Parent.votin.votes.votesgiven
local val2 = script.Parent.votin.timeleft.decreasing
local gui = script.Parent

remEvent2.OnServerEvent:Connect(function()
    script.Parent.votin.timeleft.Text = "15"
    wait(1)
    script.Parent.votin.timeleft.Text = "14"
    wait(1)
    script.Parent.votin.timeleft.Text = "13"
    wait(1)
    script.Parent.votin.timeleft.Text = "12"
    wait(1)
    script.Parent.votin.timeleft.Text = "11"
    wait(1)
    script.Parent.votin.timeleft.Text = "10"
    wait(1)
    script.Parent.votin.timeleft.Text = "9"
    wait(1)
    script.Parent.votin.timeleft.Text = "8"
    wait(1)
    script.Parent.votin.timeleft.Text = "7"
    wait(1)
    script.Parent.votin.timeleft.Text = "6"
    wait(1)
    script.Parent.votin.timeleft.Text = "5"
    wait(1)
    script.Parent.votin.timeleft.Text = "4"
    wait(1)
    script.Parent.votin.timeleft.Text = "3"
    wait(1)
    script.Parent.votin.timeleft.Text = "2"
    wait(1)
    script.Parent.votin.timeleft.Text = "1"
    wait(1)
    script.Parent.votin.timeleft.Text = "0"
    wait(0.1)
    script.Parent.votin.notifier.Visible = true
    wait(3)
    binEvent:Fire()
end)

Receive fire (LocalScript In StarterPlayerScripts)

local binEvent = game.ReplicatedStorage.Bindables:WaitForChild("Event")
local camera = workspace.CurrentCamera

binEvent.Event:Connect(function()
    camera.CameraType = Enum.CameraType.Custom
end)

Any working answer is appreciated.

0
Hey, aren't bindable events only restricted to communication between server scripts and other server scripts? RAFA1608 543 — 3y
0
Also, I'd suggest using a for loop for that timeleft thing. It is really simple to use, and it really pays off once you learn how to use it. RAFA1608 543 — 3y

2 answers

Log in to vote
1
Answered by
NGC4637 602 Moderation Voter
3 years ago

as RAFA1608 has stated, BindableEvents are for communicating from server script to server script. You should use a remote event and use FireAllClients instead of bin event and Fire.

and also replace Event event with OnClientEvent

0
the api reference also states: BindableEvents do not allow for communication between the server and client. If you are looking for this functionality use RemoteEvent. NGC4637 602 — 3y
Ad
Log in to vote
0
Answered by
0hsa 193
3 years ago

sorry if comments are not useful english is not my first language

LOCALscript in startergui (do not use server script in startergui)

local ReplicatedStorage = game:GetService "ReplicatedStorage"
local RemoteEvents = {
    ReplicatedStorage.Remotes.RemoteEvent;
    ReplicatedStorage.Remotes.RemoteEvent2; -- [[ Change these to bindable events OR Change bindable to remote and make this server script again. ]]
    ReplicatedStorage.Remotes.RemoteEvent3;
}
local Bindable = ReplicatedStorage.Bindables.Event

local Gui = script.Parent

local votesgiven = Gui:WaitForChild("votin"):WaitForChild("votes"):WaitForChild("votesgiven")\
local notifier = Gui.votin.notifier
local timeleft = Gui.votin.timeleft
local decreasing = timeleft:WaitForChild("decreasing")

RemoteEvents.OnServerEvent--[[ Change this too if you change the remote events ]]:Connect(function()
    for i = 15, 0, -1 do
        timeleft.Text = tostring(i)
        wait(1)
    end

    wait(0.1)

    notifier.Visible = true
    wait(3)
    Bindable:Fire()--[[ Change if you change bindable ]]
end)

other script

local ReplicatedStorage = game:GetService "ReplicatedStorage"
local Bindable = ReplicatedStorage.Bindables.Event
local Camera = workspace.CurrentCamera

Bindable.Event--[[ Change if you changed the bindable ]]:Connect(function()
    Camera.CameraType = Enum.CameraType.Custom
end)
0
I get an error. "OnServerEvent" can only be used on the server. 2_MMZ 1059 — 3y
0
Thank you! 2_MMZ 1059 — 3y

Answer this question