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

How do I change a property of a part locally?

Asked by 5 years ago
Edited 5 years ago

I tried making my own script. But it din't work. :( My script is:

01-- This is a local script!
02 
03local playerService = game:GetService("Players")
04local TEAMS = game:GetService("Teams")
05local localPlayer = playerService.LocalPlayer
06 
07script.Parent.Touched:Connect(function(hit)
08    if hit == localPlayer then
09        if localPlayer.team  == TEAMS:FindFirstChild("A team name") or TEAMS:FindFirstChild("Another team name") or TEAMS:FindFirstChild("High Level") then -- The team names are right.
10            script.Parent.CanCollide = false
11            wait(0.5)
12            script.Parent.CanCollide = true
13        else
14            print("Not a allowed in!")
15        end
16    else
17        print("Something went wrong. ¯\(°_o)/¯")
18    end
19end)

If you can either help me correct the script or give me something to read/script, please help me. - Toby

0
Take a look at how "OR" conditionals work also, the localPlayer you defined is a player instance. when comparing hit you want to use the players character. ForeverBrown 356 — 5y
0
I see an error on line 08. You're saying if hit is the same as the player when the player is an object in Players and the Character which would be touching the part is in Workspace. So try something like if hit.Parent.Name == localPlayer.Name then -- Do stuff end namespace25 594 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Okay, so here is what I suggest. Putting a LocalScript into StarterPlayerScripts and adding this script.

01-- This is a local script!
02 
03local playerService = game:GetService("Players")
04local TEAMS = game:GetService("Teams")
05local localPlayer = playerService.LocalPlayer
06local Part = game.Workspace.Part --Make a variable for the part here that you want touched.
07 
08Part.Touched:Connect(function(hit)
09     local Humanoid = hit.Parent:FindFirstChild("Humanoid")
10    if (Humanoid ~= nil) then
11        if localPlayer.Team  == TEAMS:FindFirstChild("A team name") or TEAMS:FindFirstChild("Another team name") or TEAMS:FindFirstChild("High Level") then -- The team names are right.
12            Part.CanCollide = false
13            wait(0.5)
14            Part.CanCollide = true
15        else
View all 21 lines...

I hope this helping you out!

Ad
Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

A Player’s Backpack, such as a child of a Tool A Player’s character model A Player’s PlayerGui A Player’s PlayerScripts. The ReplicatedFirst service

Other than that other answers should be ok.

Read more here

Answer this question