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

Help Firing from Server to Client?

Asked by 5 years ago

I'm trying to code a simple outline for a block that infects you with a virus, and I'm trying to send the server script to a LocalScript for easier changing of player values, etc.

My current script (which is inside of the part that you need to walk on) is this:

--Variables

local Players = game:GetService("Players")
local pressed = false

--Script

script.Parent.Touched:Connect(function(hit) 

    if hit.Parent:FindFirstChild("Humanoid") then

        if not pressed then

            pressed = true

            local chance = math.random(1,10) 
            local incubation = math.random(60, 120)

            print("FVZ-112 Script Fired.")

            local event = Instance.new("RemoteEvent")
            event.Parent = game.ReplicatedStorage.Viruses.FVZ112
            event.Name = "onTouched"

            print("Event Defined.")

            local function onTouched(player)
                event:FireClient(player)
            end

            script.Parent.Touched:Connect(onTouched)

            print("Event Fired")
            wait(5)
            pressed = false

        end
    end 
end)


The problem is that when I step on the button, in the output it says "FireClient: player argument must be a Player object"

I know that the incubation and chance values aren't doing anything currently, but I'll implement them once I've made sure the script works.

0
try changing the remote event name, the name of an object can interfere with the script. such as naming an object Color. mantorok4866 201 — 5y

1 answer

Log in to vote
0
Answered by
BashGuy10 384 Moderation Voter
5 years ago
Edited 5 years ago

The BasePart.Touched event has a special argument that returns the part that touched

Here is a simple script getting the player

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        print(player.Name) -- Prints the players name, so it would print "BashGuy10"
    end
end)

So, in your case it would be:

--Variables

local Players = game:GetService("Players")
local pressed = false

--Script

script.Parent.Touched:Connect(function(hit) 

    if hit.Parent:FindFirstChild("Humanoid") then

        if not pressed then

             pressed = true

            local chance = math.random(1,10) 
            local incubation = math.random(60, 120)

            print("FVZ-112 Script Fired.")

            local event = Instance.new("RemoteEvent")
            event.Parent = game.ReplicatedStorage.Viruses.FVZ112
            event.Name = "onTouched"

            print("Event Defined.")

            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

            event:FireClient(plr)

            print("Event Fired")
            wait(5)
            pressed = false

        end
    end 
end)


OH LOOK ITS A FREE WIKI LINK

0
Mark this as the answer if it helped! BashGuy10 384 — 5y
Ad

Answer this question