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

button makes arm colored while using rEvent. but, i can't utilize a localplayer inside a script?

Asked by 5 years ago

This script allows the player to color their arm with a press of a button. But since it won't work without RemoteEvents, i tried to improvise.

However, when I did this, I ran into another error. How would I utilize a script that needs the localplayer when it's a normal script? So i tried to use playeradded. However it didn't work.

Does anyone have a solution?

Goal: Button "F" is supposed to change your arm to the color blue, and it's supposed to be visible to everybody (hence the use of RemoteEvents), but I can't do this on a normal script, because I can't utilize the localplayer.

Try this for yourself in Studio, use two players. And you'll see. On one player you can press "F" and it works. However, there's another bug, and it ends up making EVERYBODYS arm blue.

Can anyone help?

Script:

local tEvent = Instance.new("RemoteEvent")
tEvent.Name = "tEvent"
tEvent.Parent = script.Parent.Parent.ReplicatedStorage

game.Players.PlayerAdded:Connect(function(Player)

    local Character = Player.Character or Player.CharacterAdded:wait()

    local LUarm = Character:WaitForChild("LeftUpperArm")
    local CLUarm = LUarm:Clone()

    tEvent.OnServerEvent:Connect(function()

        print("Fired!")
        Player.Character.Humanoid.MaxHealth = 500

        CLUarm.CanCollide = false
        CLUarm.Anchored = false
        CLUarm.Color = Color3.new("Electric blue")
        CLUarm.Material = "Foil" 
        CLUarm.Size = Vector3.new(1.01, 1.2, 1.01)
        CLUarm.Parent = LUarm


    end)
end)


LocalScript:

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local tEvent = game.ReplicatedStorage:WaitForChild("tEvent")

repeat wait() until tEvent


local used = false

-- function
local function onInputBegan(input,gameProcessed)

    if input.KeyCode == Enum.KeyCode.F and used  == false then

        used = true

        tEvent:FireServer()


    elseif

        used == true then return end

end
UserInputService.InputBegan:connect(onInputBegan)

1 answer

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

Hey there, I think this can help ya; the first parameter of the OnServerEvent's function is always the player who fired the event. So your server script needs to be like this:


local tEvent = Instance.new("RemoteEvent") tEvent.Name = "tEvent" tEvent.Parent = script.Parent.Parent.ReplicatedStorage tEvent.OnServerEvent:Connect(function(Player) -- Player who fired the event local Character = Player.Character or Player.CharacterAdded:wait() local LUarm = Character:WaitForChild("LeftUpperArm") local CLUarm = LUarm:Clone() print("Fired!") Player.Character.Humanoid.MaxHealth = 500 CLUarm.CanCollide = false CLUarm.Anchored = false CLUarm.Color = Color3.new("Electric blue") CLUarm.Material = "Foil" CLUarm.Size = Vector3.new(1.01, 1.2, 1.01) CLUarm.Parent = LUarm end)
0
thank you man! jesusbeef 33 — 5y
0
No problem! Zologo 37 — 5y
Ad

Answer this question