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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Ruves 21
4 years ago

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.

Ad
Log in to vote
0
Answered by
Sorukan 240 Moderation Voter
4 years ago
Edited 4 years ago

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)
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.. Sorukan 240 — 4y

Answer this question