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

Morph Pad being touched doesn't trigger a overhead gui to appear above head?

Asked by 5 years ago

I'm new to scripting, and I've been watching various tutorials to try and make a script that uses remote events to trigger an overhead GUI (a title) to appear over a single person's head permanently that everyone else can see.

The way I want it to trigger is through touching a morph pad, which is just a Part with several scripts inside it for welding various parts to the character.

I'm still inexperienced, and I apologize in advance.

The two relevant scripts (a localScript and a Script) i have so far look like this:

LocalScript (parent is Morph, the pad, which is part of a model being part of Workspace):

script.Parent.Touched:Connect(onTouch)

    function onTouch(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
     local Debounce = false 
    if Debounce == false then
            Debounce = true
    game.ReplicatedStorage.RemoteEvent:FireServer()
    print ("Remote Event has fired.")
    wait(0.1)
    Debounce = false
        end
        end
    end

script.Parent.Touched:connect(onTouch)

Script (located in ServiceScriptService currently):

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()

    local billboardgui = game.GetService("ReplicatedStorage"):WaitForChild("BillboardGui")

    local player = game.Players.LocalPlayer

    local character = player.Character or player.CharacterAdded:Wait()

    local humanoid = character:WaitForChild("Humanoid")

    local clonedgui = billboardgui:Clone()
    clonedgui.TextLabel.Text = "~Black Queen~"
    clonedgui.TextLabel.TextColor3 = Color3.fromRGB(252,0,10)
    clonedgui.TextLabel.TextStrokeColor3 = Color3.fromRGB(103,0,1)
    clonedgui.TextLabel.Font = "Bodoni"
    clonedgui.Parent = game.Workspace.WaitForChild(player.Name).Head

    print("Event has fired.")
end)

There was no errors that popped up in the console, but the print() events did not fire, and the overhead gui didn't appear over my head when I touched the pad.

Again, I apologize for any problems I have that could have been prevented.

Thank you for reading.

0
I would love more links/tips about which parts of the explorer are client or server-based. However, there was two errors that popped up when using this script. sonicvsmaio4 4 — 5y
0
The first error was "BindableEvent is not a valid member of ReplicatedStorage" at Line 1 of the SSS script. The second error was "Unable to cast value to Object" At line 5 in the Part script. sonicvsmaio4 4 — 5y
0
Okay, learned something new and fixed the 1st error, just needed to add a BindableEvent and label it as such. Still cannot fix the second error at this point in time, but there might be a breakthrough. sonicvsmaio4 4 — 5y
0
Okay, fixed the second error by changing the "hit.parent" to not be a string and fixed a spelling error, and the bindable event fired! Progress! Now though, I ran across a third error, which was line 3 of the SSS script with "ServerScriptService.RecievingBindScript:4: attempt to index local 'Player' (a nil value)" Let's try to get another breakthrough. sonicvsmaio4 4 — 5y
View all comments (2 more)
0
Okay, I seemed to have fixed the third error when I replaced "Char" with "Player" in the Part Script asking to fire, and both print events fire. However, nothing happened until I replaced the "Char.Head" with the game.Workspace:WaitForChild(Player.Name).Head and then it worked. Only issue now is learning how to offset it so it's ABOVE the head. One last breakthrough. sonicvsmaio4 4 — 5y
0
Okay, I was able to figure out how to display it without clipping it through the head by using StudsOffset. So at this point, i consider the inital question answered and solved. However, I do want to figure out how to make it so that GUI perserves perspective (AKA bigger when closer, smaller when further away). Thank you so much though. sonicvsmaio4 4 — 5y

1 answer

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

It is important to note that you can not use LocalScripts in parents that are not client replicated. Since you have a LocalScript inside of a Part that is inside of a Model that is inside of Workspace, the LocalScript will not run since it is not being run from the client. In order to solve the problem, there should be a Script inside of the part instead of a LocalScript.

Furthermore, since you are using a Script to communicate with another Script, you need to use a BindableEvent rather than a RemoteEvent. RemoteEvents are used to communicate between the Client and Server, but in this case, you are only communicating between two Scripts.

Script inside of part:

local Part = script.Parent
local Debounce = false

Part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil and not Debounce then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        Debounce = true
        game.ReplicatedStoarge.BindableEvent:Fire(Player)
        print("Bindable Event was fired")
        wait(0.1)
        Debounce = false
    end
end)

Script Inside of ServerScriptService:

game.ReplicatedStorage.BindableEvent.Event:connect(function(Player)
    local BillboardGui = game.ReplicatedStorage:WaitForChild("BillboardGui"):clone()
    local Char = Player.Character

    BillboardGui.TextLabel.Text = "~Black Queen~"
    BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(252, 0, 10)
    BillboardGui.TextLabel.TextStrokeColor3 = Color3.fromRGB(103,0,1)
    BillboardGui.TextLabel.Font = "Bodoni"
    BillboardGui.Parent = Char.Head

    print("Event was fired")
end)

I hope that helps! :)

Ad

Answer this question