Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this script take my player to a camera on gui button click?

I wrote this script to try and close the guis that were previously open and switch the player to a camera. I've been trying to fix this and I can't figure out why it won't switch the player to the cam.

local hats = script.Parent.Parent

script.Parent.MouseButton1Down:connect(function(click)
	if click.Parent:FindFirstChild("Humanoid") then
	hats.Visible = false
	hats.Parent.Outfits.Visible = false
	local player = game.Players:GetPlayerFromCharacter(click.Parent)
game.ReplicatedStorage.TriggerCamE:FireClient(player)
end
end)


2 answers

It is to my knowledge that the server can't edit the players camera, only the player. I may be wrong but I'd give it a shot.

The line where you wrote Click.Parent, wouldn't work since the the parameter of MouseButton1Down does not include anything that's part of the character model.

https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Down

local hats = script.Parent.Parent
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
    hats.Visible = false
    hats.Parent.Outfits.Visible = false
    game.ReplicatedStorage.TriggerCamE:FireServer()
end)

1 comment

0

Also, i'm not sure what's your purpose of checking if the player who clicked it has a humanoid because only players can click the GUI anyways, and yeah, it seems like you're doing this on a server script since you're using FireClient so use a local script for it instead..

This discussion is preserved as it was. New answers, comments, and votes are closed.