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

Broken plate script and output stopped helping. Can you guys help?

Asked by 4 years ago

Im trying to make a spoopy game (idk why) and i wanted to start it by having someone walk into a house and when they enter the doorway it put a text label with some spoopy stuff but it isnt working and output stopped telling me stuff this is the local script portion

local Player = game.Players.LocalPlayer
local PlateEvent = game.ReplicatedStorage.PlateEvent
local YWDH = script.Parent


function YWDHF()
    YWDH.Text = "ERROR"
    YWDH.Visible = true
    wait(0.5)
    YWDH.Text = "YOU WILL DIE HERE"..Player.Name
    wait(2)
    YWDH.Text = "ERROR"
    wait(0.5)
    YWDH:Destroy()
end

PlateEvent.OnClientEvent:Connect(YWDHF)

and this is the plate script portion

local Plate = script.Parent
local PlateEvent = game.ReplicatedStorage.PlateEvent

Plate.Touched:Connect(function(hit, player)
    if hit.Parent == player then
        PlateEvent:FireClient()
    end
end)

as i said output stopped talking so idk what to do some help would be really appreciated ive had good experiences with you before so now i need help (was unfairly banned from the discord server so had to come here)

2 answers

Log in to vote
1
Answered by
pwx 1581 Moderation Voter
4 years ago

A Touched event does not give off a parameter for player, only hit. But you can use Players Service to find the player through hit.

On your Server script, try:

local Plate = script.Parent
local PlateEvent = game.ReplicatedStorage.PlateEvent
local Players = game:GetService('Players')

Plate.Touched:Connect(function(hit)
    local Player = Players:GetPlayerFromCharacter(hit.Parent) -- using the service to check for a player
    if Player then -- check if player exists
        PlateEvent:FireClient(Player) -- always put the player when firing a client
    end
end)
0
Also change his local script for him, he doesn't define player in his function. I would do it but I like your answer better lol. cmgtotalyawesome 1418 — 4y
0
Thanks mantinmany 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The Touched event only gives you the part that touched what you are connecting and nothing else. All you need to do to fix the script is take out the player variable from the parentheses and instead of checking if hit.Parent == player just check for a humanoid. This would make your script look like this:

local Plate = script.Parent
local PlateEvent = game.ReplicatedStorage.PlateEvent

Plate.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        PlateEvent:FireClient()
    end
end)

The reason we check for a humanoid is because every player in the game will have one. If your game has npcs that move around I would recommend checking if their name is in the players list because this event will be triggered by any roaming npc that comes into contact with the parts.

Hope I helped!

Edit:

If you ever find yourself in a situation where the output isn't giving any errors, you can use a warn or print to debug yourself. An example of this would be down below:

local Plate = script.Parent
local PlateEvent = game.ReplicatedStorage.PlateEvent
Plate.Touched:Connect(function(hit, player)
    if hit.Parent == player then
        PlateEvent:FireClient()
        warn("Event Fired")
    end
end)

This block of code would make it to where if the event was fired then yellow text would appear in the output which displays whatever string you put in the parentheses. If this doesn't display in the output, your if statement didn't pass and you would know what to look at to debug.

Answer this question