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

How to make a GUI inside .Touched only change for one person?

Asked by 6 years ago

When a player touches the part the GUI (fadeScreen) is supposed to only change for the player that touched the part, but it changes for all players.

This is a local script inside StarterGui

local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local fadeScreen = playergui.Travel.FadeScreen

place = CFrame.new(206.25, -159.5, -1833)


function fadeIn(GUI)

    fadeScreen.Visible = true
    fadeScreen.BackgroundTransparency = 1

    for i = 1, 150 do
      wait(0.01)
      fadeScreen.BackgroundTransparency = fadeScreen.BackgroundTransparency - 0.01
    end

end



game.Workspace.Part1.Touched:Connect(function(hit)

    if debounce == false then return end
    debounce = false

    if hit then
    if hit.Parent:FindFirstChild('Humanoid') and game.Players:FindFirstChild(hit.Parent.Name) then

    local plr = game.Players:FindFirstChild(hit.Parent.Name)

    fadeIn()
    plr.Character.HumanoidRootPart.CFrame = place

    end
    end

    wait(10)
    debounce = true
end)

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

For realise this, i propose use RemoteEvent.

Put in ReplicatedStorage a RemoteEvent. In ur part put a ServerScript "Script". In this script write this.

local Event = game:GetService('ReplicatedStorage').RemoteEvent

script.Parent.Touched:Connect(function(hit)
    local Player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
    if Player then
        Event:FireClient(Player)
    end
end)

now that this is done, in ur ClientScript "LocalScript" write this.

local Event = game:GetService('ReplicatedStorage').RemoteEvent

local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local fadeScreen = PlayerGui.Travel.FadeScreen

Debounce = true
place = Vector3.new(206.25, -159.5, -1833)

function fadeIn()

    fadeScreen.Visible = true
    fadeScreen.BackgroundTransparency = 1

    for i = 1, 150 do
        wait(0.01)
        fadeScreen.BackgroundTransparency = fadeScreen.BackgroundTransparency - 0.01
    end
end

Event.OnClientEvent:Connect(function()
    if Debounce then
        Debounce = false
        fadeIn()
        Player.Character:MoveTo(place)
        Debounce = true
    end
end)

I'm on mobile so I could not test but it should work.

Accepte my awnser if it work.

1
Works like a charm! Thank you! xXrawr_xdXxOwO 24 — 6y
Ad

Answer this question