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

RemoteEvent not getting taken up by another script?

Asked by 4 years ago

I have button and when I touch it I want the thing to happen to one client so I use a remote event and fire a Client function and then I have a local script inside of StarterGui to take it up but when I touch the button nothing happens, output doesn't print anything and it doesn't show any errors aswell. I'm gonna give you all scripts that are involved in this and hope you find a solution thank you.

--SERVERSCRIPT, WORKSPACE

local playerEvent = game:GetService("ReplicatedStorage").Player

local function onTouched(player)
    if player:FindFirstChild("Humanoid") then
        local playerObj = player:GetPlayerFromCharacter(player.Parent)

        playerEvent:FireClient(playerObj)
    end
end

script.Parent.Touched:Connect(onTouched)

2nd script

-- LOCAL SCRIPT, STARTERGUI

local playerEvent = game:GetService("ReplicatedStorage").Player
local playerEventTwo = game:GetService("ReplicatedStorage").Player2

playerEvent.OnClientEvent:Connect(function()

    local activatedParts = game.Workspace["Very Easy"].ActivatedParts:GetChildren()

    for i,v in pairs(activatedParts) do

        v.CanCollide = true
        v.Transparency = 0

    end

    game.Workspace["Very Easy"].Button1.Color = Color3.fromRGB(255, 0, 0)

end)

playerEventTwo.OnClientEvent:Connect(function()

    local activatedParts = game.Workspace["Very Easy"].ActivatedParts2:GetChildren()

    for i,v in pairs(activatedParts) do

        v.CanCollide = true
        v.Transparency = 0

    end

    game.Workspace["Very Easy"].Button2.Color = Color3.fromRGB(255, 0, 0)

end)

1 answer

Log in to vote
1
Answered by
Befogs 113
4 years ago

The Touched event returns the part that hit it. So if you hit your part, touched may return something like RightFoot. In your server script, you're expecting that it would return the player's character, but this isn't what's happening. To get the player's character you'll just want to get the hit part's parent. Here's an example on how this could be rewritten.

local function onTouched(hit)
    local playerObj = game.Players:GetPlayerFromCharacter(hit.Parent)
    if playerObj then
        local player = hit.Parent

        playerEvent:FireClient(playerObj)
    end
end

Here we check if the hit's parent is a player, and if so then we get their character and fire the event!

0
Thanks! ZombieApocalypz3 35 — 4y
Ad

Answer this question