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

How to change the text label to show winner?

Asked by
MicNasr -5
5 years ago
Edited by User#24403 5 years ago
local trapPart = script.Parent
local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
       _G.risespeed = 0.02
      game.StarterGui.ScreenGui.TextLabel.Text = humanoid.Name .. " has won!"
    wait (5)
    humanoid.Health = 0
    end
end
trapPart.Touched:Connect(onPartTouch)

This code checks for the player if he touched it, then it makes the risespeed faster and SHOULD change the text label to playerthattouchedtheobject has won! But it only shows humanoid has won. Also It only updates the text when the player dies and not right after touching it which should be it. Anyone could help me with both issues? finding player name that touched it and making it appear when touched and not when he dies.

Any Help would be appreciated

1 answer

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

First off don't use _G. Instead use bindables and/or module scripts. Second off you're changing the GUIs in StarterGui, which isn't a specific player's PlayerGui. The changes made in your current code won't be applied until the player resets. Even then, the server should never ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever,

EVER

handle user interface or user input or know about it.

What you can do is use remote events. They allow for client <-> server communication. If you don't know how to use them read this answer here, and even use the developer hub too.

Inside your text label, you might wanna have a local script with code kinda like this;

-- define remoteEvent
remoteEvent.OnClientEvent:Connect(function(text)
    script.Parent.Text = text
end)

And your server code just needs to fire this remote.

local trapPart = script.Parent
local riseSpeed = 0
local Players = game:GetService("Players")

trapPart.Touched:Connect(function(part)
    local client = Players:GetPlayerFromCharacter(part.Parent)

    if client then
        riseSpeed = riseSpeed + 0.02
        remoteEvent:FireAllClients(client.Name .. " has won!")
        wait(5)
        client.Character:BreakJoints()
    end
end)

Notice I don't use the method of finding a humanoid as it is unreliable. Anything can have a humanoid, even non-players!

0
Okay so the second code should be in the workspace as a remote event and thats it? MicNasr -5 — 5y
0
removeevent in code 1 is saying that it dosent recognise the global MicNasr -5 — 5y
0
Because this code isn't copy paste friendly on purpose. And remotes should be in replicated storage. I'm pretty sure,you know how to declare variables so remote event isn't unrecognized User#24403 69 — 5y
Ad

Answer this question