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

(CLOSED) How do I make this GUI go Client-Side instead of Server-Side?

Asked by
Slatryte 104
4 years ago
Edited 4 years ago

Introduction

So I am working on a Hotel game in which when you touch the computer, a GUI opens. The only problem is that the GUI doesn't only open for one person, it opens for the whole server!

Here are the scripts I used:

local GUI = script.Parent
local part = game.Workspace.coolyoungpart
part.Touched:Connect(function()
    game.StarterPlayer.Value.Value = 1
end)
local GUI = script.Parent
local val = game.StarterPlayer.Value
if val.Value == 1 then
    GUI.Enabled = true
end
if val.Value == 0 then
    GUI.Enabled = false
end
val.Changed:Connect(function()
    if val.Value == 1 then
    GUI.Enabled = true
    end
    if val.Value == 0 then
    GUI.Enabled = false
end
end)
local button = script.Parent
local GUI = script.Parent.Parent.Parent
button.MouseButton1Click:Connect(function()
    game.StarterPlayer.Value.Value = 0
end)

Yeah, and that's it.

Conclusion

Can somebody help me?

2 answers

Log in to vote
0
Answered by 4 years ago

Hello dear friend! Let me help you with this problem.

First off, I don't suggest using IntValues as a method of toggling.

Secondly, let me fix your scripts.

For your first one, you need to make sure the object touching the part is a Humanoid.

Insert a RemoteEvent and write:

local toggle = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:WaitForChild('Humanoid') then
        game.ReplicatedStorage.RemoteEvent:FireClient()
    end
end)

Then, add a LocalScript inside of your ScreenGui and write in:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    script.Parent.Enabled = true
end)

Lastly, insert a LocalScript inside of the Close button of your GUI and write in:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Enabled = false
end)

What are RemoteEvents?

RemoteEvents are things that serve as a solution to the server-client side problem. To learn more, go here

Ad
Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
4 years ago

I see what you are trying to do, but seems like you've going into more troubles than you need to!

To give a GUI to a player is fairly simple, you just clone it into the player's PlayerGui!

local gui = script.Parent.Parent

-- function to give a playera gui
local function giveGuiTo(player)

    -- we clone the original GUI and parent it to the Player's PlayerGui
    gui:Clone().Parent = player.PlayerGui
end

It's simple as that! If you wish to use the Touch event, then listen to it, find the player, and call the function or even directly write the code!

local players = game:GetService("Players") -- The player service
local gui = script.Parent.Parent

-- function to give a playera gui
local function giveGuiTo(player)

    -- we clone the original GUI and parent it to the Player's PlayerGui
    gui:Clone().Parent = player.PlayerGui
en

part.Touched:Connect(function(hit) 
    local humanoid = hit.Parent:FindFirstChild("Humanoid")

    -- we make sure that it's a human by checking for a humanoid
    if(humanoid) then
        local character = humanoid.Parent -- if it is a player, then the humanoid's parent is the character!

        -- GetPlayerFromCharacter() gets the player from a character
        local player = players:GetPlayerFromCharacter(character)

        -- if there is indeed a player then
        if(player) then
            giveGuiTo(player)
        end
    end
end)
0
well uh, nice troll crashing my studio? Slatryte 104 — 4y

Answer this question