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)
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!
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