如何在砖块被触摸时运行本地脚本?

所以,我想在玩家客户端上运行一个脚本,基本上激活2个-1饱和度颜色校正效果,以反转它们屏幕上的颜色,只有他们的屏幕,但我只写了几个月的脚本,不太能写复杂的代码。

以下是代码:

   game.Workspace.Five.Touched:Connect(function(hit)
        if hit.Parent == game.Players.LocalPlayer.Character then
            game.Lighting.inverted1.Enabled = true
            game.Lighting.inverted2.Enabled = true
        end
    end)
点赞
用户15107943
用户15107943

将本地脚本放置在 StarterPlayerScripts 中。

enter image description here

我以稍微更好的方式重写了你的代码。将此代码放置在本地脚本中。

Lighting = game:GetService('Lighting')

game.Workspace.Five.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild('Humanoid') then
      print('Runned')
      Lighting.inverted1.Enabled = true
      Lighting.inverted2.Enabled = true
   end
 end)

建议使用 game:GetService('Service name') 来使用服务。我还将 if hit.Parent == game.Players.LocalPlayer.Character then 更改为 if hit.Parent:FindFirstChild('Humanoid') then,因为它更简单,而且代码运行速度比角色加载要快,所以它会出错并停止运行。与 getService() API 参考链接:https://developer.roblox.com/en-us/api-reference/function/ServiceProvider/getService

2021-02-10 01:13:39
用户15177920
用户15177920

好的,我已经解决了,使用远程事件我获取了触摸砖块的玩家,并使用服务器来处理颜色校正使能。

2021-03-01 19:01:56