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

How do I make this happen locally?

Asked by 1 year ago

This script makes a part's (pointPart's) color change from blue to green, makes 2 models transparent, adds one point to the leaderboard when someone touches pointPart, and makes it so nobody can get a leaderstat point by touching pointPart again. I want to make the color change and the transparency change locally, not globally, and I want to make it so that only the person who touches pointPart cannot get a leaderstat point by touching it again, but everyone else can. Making the script a local script doesn't work, how do I do this?

local pointPart = script.Parent
-- Colors
local blue = Color3.fromRGB(0, 0, 255)
local green = Color3.fromRGB(0,255,0)

-- Services needed
local Players = game:GetService("Players")
local canGet = true

local function onTouch(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    local currentColor = pointPart.Color
    local model = script.Parent.Parent.Gear
    if humanoid and player and canGet and currentColor == blue then
        canGet = false
        player.leaderstats.Gears.Value = player.leaderstats.Gears.Value + 1
        print("Giving player gear")
        pointPart.Color = green
        for i, block in model:GetChildren() do
            if block:IsA("Part") or ("UnionOperation") then
                block.Transparency = 0.5
            elseif humanoid and player and canGet and currentColor == green then
                print("Player already recieved gear")
            end
        end
    end
end


local function onTouch2(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
    local currentColor = pointPart.Color
    local model = game.Workspace.Fakegear
    if humanoid and player and canGet and currentColor == blue then
        wait(5)
        for i, block in model:GetChildren() do
            if block:IsA("Part") or ("UnionOperation") then
            block.Transparency = 0.5
            canGet = true
            end
        end 
    end
end

pointPart.Touched:Connect(onTouch)
pointPart.Touched:Connect(onTouch2)
0
Maybe if its a localscript make the player val local player = game.Players.LocalPlayer Xx_ashcarter13 17 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago

If you want something to change locally, you will have to use a local script. The local script has to be in either StarterPlayerScripts, StarterCharacterScripts, StarterPack or StarterGui.

You will need to use a Remote Event to have a server script and a local script communicate with each other.

You want the local script to change the colors when the Remote Event is fired from the server.

I hope this helped!

0
Thanks, I don't really know how to get this to work. I posted an answer with the code I attempted to put together, but I can't get it to work and I'm confused BunjiBloxxer 51 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

I'm confused as to how all of this works. I made a Remote Event in Replicated Storage named "GearGet" I then tried moving the script to a local script and put it in starter player scripts, after tweaking it a little:

local replicatedStorage = game.ReplicatedStorage
local GearGetRemote = replicatedStorage:WaitForChild("GearGet")

local pointPart = game.Workspace.FullGear.GearGiver
-- Colors
local blue = Color3.fromRGB(0, 0, 255)
local green = Color3.fromRGB(0,255,0)

-- Services needed
local Players = game:GetService("Players")
local canGet = true

GearGetRemote.OnClientEvent:Connect(function (otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
local currentColor = pointPart.Color
local model = game.Workspace.FullGear.Gear
if humanoid and player and canGet and currentColor == blue then
    canGet = false
    player.leaderstats.Gears.Value = player.leaderstats.Gears.Value + 1
    print("Giving player gear")
    pointPart.Color = green
    for i, block in model:GetChildren() do
        if block:IsA("Part") or ("UnionOperation") then
            block.Transparency = 0.5
        elseif humanoid and player and canGet and currentColor == green then
            print("Player already recieved gear")
        end
    end
end
end)

(I'm ignoring the "onTouch2" function from the original script for now) I also have a server script in Server Script Service that says this:

local replicatedStorage = game.ReplicatedStorage
local GearGetRemote = replicatedStorage:WaitForChild("GearGet")

GearGetRemote.OnServerEvent:Connect(function(player,...)
    print(player.Name)
    print(...)
end)

GearGetRemote:FireAllClients()

I don't know how to fire the GearGet Remote event when someone touches pointPart though. I feel like I'm over thinking it, I looked up a yt tutorial on how to use Remote Events and I don't really understand it

Answer this question