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 2 years 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?

01local pointPart = script.Parent
02-- Colors
03local blue = Color3.fromRGB(0, 0, 255)
04local green = Color3.fromRGB(0,255,0)
05 
06-- Services needed
07local Players = game:GetService("Players")
08local canGet = true
09 
10local function onTouch(otherPart)
11    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
12    local player = game.Players:FindFirstChild(otherPart.Parent.Name)
13    local currentColor = pointPart.Color
14    local model = script.Parent.Parent.Gear
15    if humanoid and player and canGet and currentColor == blue then
View all 48 lines...
0
Maybe if its a localscript make the player val local player = game.Players.LocalPlayer Xx_ashcarter13 17 — 2y

2 answers

Log in to vote
0
Answered by 2 years 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 — 2y
Ad
Log in to vote
0
Answered by 2 years 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:

01local replicatedStorage = game.ReplicatedStorage
02local GearGetRemote = replicatedStorage:WaitForChild("GearGet")
03 
04local pointPart = game.Workspace.FullGear.GearGiver
05-- Colors
06local blue = Color3.fromRGB(0, 0, 255)
07local green = Color3.fromRGB(0,255,0)
08 
09-- Services needed
10local Players = game:GetService("Players")
11local canGet = true
12 
13GearGetRemote.OnClientEvent:Connect(function (otherPart)
14local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
15local player = game.Players:FindFirstChild(otherPart.Parent.Name)
View all 31 lines...

(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:

1local replicatedStorage = game.ReplicatedStorage
2local GearGetRemote = replicatedStorage:WaitForChild("GearGet")
3 
4GearGetRemote.OnServerEvent:Connect(function(player,...)
5    print(player.Name)
6    print(...)
7end)
8 
9GearGetRemote: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