New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do I change a property of a part locally?

Asked by 12 days ago
Edited 12 days ago

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

-- This is a local script!

local playerService = game:GetService("Players")
local TEAMS = game:GetService("Teams")
local localPlayer = playerService.LocalPlayer

script.Parent.Touched:Connect(function(hit)
    if hit == localPlayer then
        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.
            script.Parent.CanCollide = false
            wait(0.5)
            script.Parent.CanCollide = true
        else
            print("Not a allowed in!")
        end
    else
        print("Something went wrong. ¯\(°_o)/¯")
    end
end)

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 322 — 12d
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 suspectshot108 420 — 12d

2 answers

Log in to vote
0
Answered by
Eli_90 46
12 days ago

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

-- This is a local script!

local playerService = game:GetService("Players")
local TEAMS = game:GetService("Teams")
local localPlayer = playerService.LocalPlayer
local Part = game.Workspace.Part --Make a variable for the part here that you want touched.

Part.Touched:Connect(function(hit)
     local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    if (Humanoid ~= nil) then
        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.
            Part.CanCollide = false
            wait(0.5)
            Part.CanCollide = true
        else
            print("Not a allowed in!")
        end
    else
        print("Something went wrong. ¯\(°_o)/¯")
    end
end)

I hope this helping you out!

Ad
Log in to vote
0
Answered by 12 days 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