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

Why doesn't this script that displays a GUI if a player touches a brick work?

Asked by 5 years ago
Edited 5 years ago

This script is based in a localscipt within a player's GUI (which does not reset upon respawn, if that matter).

The script detects if the localplayer's torso has touched a particular brick and then displays the GUI. It works, but once the player has died/respawned once or more, it no longer works. Output has given me nothing.

Here's the script:

local gui = script.Parent
local torso = game.Players.LocalPlayer.Character:WaitForChild("Torso")
torso.Touched:connect(function(hit)
    if hit.Name == "counter" then
        gui.Enabled = true
    end
end)
0
gui is not defined Vmena 87 — 5y
0
it is. gui = script.Parent CoolJohnnyboy 121 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You'll want to use remote events for this matter. Use a server script and a local script. The server script would be if you touch the brick then you would fire the server and on the local script you would do retrieve the remote events from the server script and make it do what you want. Example:

--//Server script local brick = script.Parent --brick is in workspace local remoteEvent = game.ReplicatedStorage.RemoteEvent --where the remote event is located

brick.Touched:Connect(function(hit) --when the player touches the brick local plr = hit.Parent:GetPlayerFromCharacter() -getting the player from character local hum = hit.Parent:FindFirstChild("Humanoid") --finds the humanoid if hum ~= nil then --checks to see if the object touched has a humanoid remoteEvent:FireServer(plr) --fires remote event end)

--//Local script local remoteEvent = game.ReplicatedStorage.RemoteEvent --where the remote event is located local screenGui = script --wherever the gui is located

remoteEvent.OnServcerEvent:Connect(function(plr) --retrieve data from fired server screenGui.Parent = plr.PlayerGui --parents the screenGui to PlayerGui

**I did not try it on studio yet, but go ahead see if it works and if it doesn't just hmu and I can further help you :)

Ad

Answer this question