Hello scripters, I’m trying to make a system where you can select which phone do you want to ring from a GUI, Unfortunately I’m really unable to do it myself. But I have tried to do it myself. More info bellow:
Here is the original script:
ocal calling = false
local caller = nil
local animation = nil
local ogspeed = 16
local ogpower = 50
local PhoneCFrame = script.Parent.Phone.CFrame
local otherphone = script.Parent.Configuration.OtherPhone.Value
function pickup()
otherphone.Click.ClickDetector.MouseClick:Wait()
otherphone.Phone.Sound:Stop()
end
function hangup()
doodgaan:Disconnect()
script.Parent.Phone.Changing.TimePosition = 1.7
script.Parent.Phone.Changing:Resume()
otherphone.Phone.Sound:Stop()
calling = false
script.CallingVal.Value = false
if animation then
animation:Stop()
end
animation = nil
caller.Character.Humanoid.WalkSpeed = ogspeed
caller.Character.Humanoid.JumpPower = ogpower
script.Parent.Phone.WeldConstraint.Part1 = nil
script.Parent.Phone.WeldConstraint.Enabled = false
script.Parent.Phone.Anchored = true
caller = nil
script.Parent.Phone.CFrame = PhoneCFrame
callsend:Disconnect()
print("stopped call")
end
function sending(msg, recipient, speaker)
local msg = tostring(msg)
local ChatService = game:GetService("Chat")
local filteredmessage=ChatService:FilterStringAsync(msg, speaker, speaker)
game:GetService("Chat"):Chat(script.Parent.Configuration.Receiver.Value.Phone,filteredmessage)
end
script.Parent.Click.ClickDetector.MouseClick:connect(function(plr)
if (plr.Character.Head.Position - script.Parent.Main.Position).Magnitude < 5 then
if not calling and caller == nil then
calling = true
script.CallingVal.Value = true
caller = plr
script.Parent.Phone.Changing.TimePosition = 0
script.Parent.Phone.Changing:Play()
animation = plr.Character.Humanoid:LoadAnimation(script.Calling)
animation:Play()
ogspeed = plr.Character.Humanoid.WalkSpeed
ogpower = plr.Character.Humanoid.JumpPower
plr.Character.Humanoid.WalkSpeed = 0
plr.Character.Humanoid.JumpPower = 0
script.Parent.Main.RopeConstraint.Attachment0 = nil
script.Parent.Phone.CFrame = plr.Character.Head.CFrame * CFrame.new(0.8, -0.25,-0.6) * CFrame.Angles(math.rad(10.29),math.rad(91.49),math.rad(-125.56))
script.Parent.Phone.WeldConstraint.Part1 = plr.Character.Head
script.Parent.Phone.WeldConstraint.Enabled = true
script.Parent.Phone.Anchored = false
if not otherphone.PhoneScript.CallingVal.Value then
otherphone.Phone.Sound:Play()
spawn(pickup)
end
script.Parent.Main.RopeConstraint.Attachment0 = script.Parent.Main.MainAttachment
doodgaan = plr.CharacterRemoving:connect(hangup)
callsend = plr.Chatted:connect(function(msg, recipient) sending(msg, recipient, plr) end)
print("started call")
wait(1)
script.Parent.Phone.Changing:Stop()
elseif calling and plr == caller then
doodgaan:Disconnect()
script.Parent.Phone.Changing.TimePosition = 1.7
script.Parent.Phone.Changing:Resume()
otherphone.Phone.Sound:Stop()
calling = false
script.CallingVal.Value = false
caller = nil
if animation then
animation:Stop()
end
animation = nil
plr.Character.Humanoid.WalkSpeed = ogspeed
plr.Character.Humanoid.JumpPower = ogpower
script.Parent.Phone.WeldConstraint.Part1 = nil
script.Parent.Phone.WeldConstraint.Enabled = false
script.Parent.Phone.Anchored = true
script.Parent.Phone.CFrame = PhoneCFrame
callsend:Disconnect()
print("stopped call")
end
end
end)
Here is my version of the script:
local calling = false
local caller = nil
local animation = nil
local ogspeed = 16
local ogpower = 50
local PhoneCFrame = script.Parent.Phone.CFrame
local otherphone = script.Parent.Configuration.OtherPhone.Value
function OnPhoneClicked(phoneName)
local selectedPhone = game.Workspace.PhoneSystem:FindFirstChild(phoneName)
if not selectedPhone then
return
end
local selectedPhoneScript = selectedPhone.PhoneScript
local selectedPhoneCallingVal = selectedPhoneScript:FindFirstChild("CallingVal")
local selectedPhoneClickDetector = selectedPhone:FindFirstChild("Click")
if selectedPhoneCallingVal and selectedPhoneClickDetector then
selectedPhoneClickDetector.MouseClick:Connect(function(plr)
if plr == caller then
hangup()
else
startCall(plr, selectedPhoneScript)
end
end)
end
end
function startCall(plr, phoneScript)
if not calling and caller == nil then
calling = true
phoneScript.CallingVal.Value = true
caller = plr
script.Parent.Phone.Changing.TimePosition = 0
script.Parent.Phone.Changing:Play()
animation = plr.Character.Humanoid:LoadAnimation(script.Calling)
animation:Play()
ogspeed = plr.Character.Humanoid.WalkSpeed
ogpower = plr.Character.Humanoid.JumpPower
plr.Character.Humanoid.WalkSpeed = 0
plr.Character.Humanoid.JumpPower = 0
script.Parent.Main.RopeConstraint.Attachment0 = nil
script.Parent.Phone.CFrame = plr.Character.Head.CFrame * CFrame.new(0.8, -0.25, -0.6) * CFrame.Angles(math.rad(10.29), math.rad(91.49), math.rad(-125.56))
script.Parent.Phone.WeldConstraint.Part1 = plr.Character.Head
script.Parent.Phone.WeldConstraint.Enabled = true
script.Parent.Phone.Anchored = false
if not otherphone.PhoneScript.CallingVal.Value then
otherphone.Phone.Sound:Play()
spawn(pickup)
end
script.Parent.Main.RopeConstraint.Attachment0 = script.Parent.Main.MainAttachment
doodgaan = plr.CharacterRemoving:Connect(hangup)
callsend = plr.Chatted:Connect(function(msg, recipient) sending(msg, recipient, plr) end)
print("started call")
wait(1)
script.Parent.Phone.Changing:Stop()
end
end
function hangup()
doodgaan:Disconnect()
script.Parent.Phone.Changing.TimePosition = 1.7
script.Parent.Phone.Changing:Resume()
otherphone.Phone.Sound:Stop()
calling = false
script.CallingVal.Value = false
caller = nil
if animation then
animation:Stop()
end
animation = nil
caller.Character.Humanoid.WalkSpeed = ogspeed
caller.Character.Humanoid.JumpPower = ogpower
script.Parent.Phone.WeldConstraint.Part1 = nil
script.Parent.Phone.WeldConstraint.Enabled = false
script.Parent.Phone.Anchored = true
script.Parent.Phone.CFrame = PhoneCFrame
callsend:Disconnect()
print("stopped call")
end
function sending(msg, recipient, speaker)
local msg = tostring(msg)
local ChatService = game:GetService("Chat")
local filteredmessage = ChatService:FilterStringAsync(msg, speaker, speaker)
game:GetService("Chat"):Chat(script.Parent.Configuration.Receiver.Value.Phone, filteredmessage)
end
script.Parent.Click.ClickDetector.MouseClick:Connect(function(plr)
if (plr.Character.Head.Position - script.Parent.Main.Position).Magnitude < 5 then
if not calling and caller == nil then
game.StarterGui.PhoneSelectorGUI.PhoneSelectionFrame.Visible = true
elseif calling and plr == caller then
hangup()
end
end
end)
function HidePhoneSelectionGUI()
game.StarterGui.PhoneSelectorGUI.PhoneSelectionFrame.Visible = false
end
OnPhoneClicked("Com1")
There is also a part named Click with a ClickDetector and a script stated bellow:
local phoneName = "Com1"
script.Parent.ClickDetector.MouseClick:Connect(function()
game.StarterGui.PhoneSelectorGUI.PhoneSelectionFrame.Visible = false
OnPhoneClicked(phoneName)
end)
Here is the script inside the GUI
local player = game.Players.LocalPlayer
local gui = player.PlayerGui.PhoneSelectionGui
local selectedPhone = nil
local function onPhoneButtonClick(phoneName)
selectedPhone = phoneName
gui.PhoneSelectionFrame.Visible = false
print("Ring the selected phone: " .. selectedPhone)
end
gui.PhoneSelectionFrame.Com1Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com1")
end)
gui.PhoneSelectionFrame.Com2Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com2")
end)
gui.PhoneSelectionFrame.Com3Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com3")
end)
gui.PhoneSelectionFrame.Com4Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com4")
end)
gui.PhoneSelectionFrame.Com5Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com5")
end)
gui.PhoneSelectionFrame.Com6Button.MouseButton1Click:Connect(function()
onPhoneButtonClick("Com6")
end)
function onPhoneClicked(part)
if part.Name == "SpecificPartName" then
gui.PhoneSelectionFrame.Visible = true
end
end
game.Players.PlayerAdded:Connect(function(player)
player.PlayerGui.ChildAdded:Connect(function(child)
if child.Name == "PhoneSelectionGui" then
child.PhoneSelectionFrame.Visible = false
end
end)
end)
Help is really apreciated
I would be also adding screenshot of the model and GUI